C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 30th, 2004, 01:54 PM
reddwarfer2002 reddwarfer2002 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 reddwarfer2002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question C++ Help

can anyone help, i need to write an ANSI C function with the following prototype: int countchar (char *str, char ch);returns the number of times a character of interest, ch appears in a string, str. (For example, 'e' appears four times in "To be or not to be: the question is illogical, Captain".)

i have to write the funtion following this pseudocode:
initialise countstart at beginning of stringwhile not at end of string if character is character of interest increment count end if move along stringend whilereturn countcan anyone help with this, plus i need help to build the full program which allows the user to input a string and then can input a character so they know how many times that charcter comes up in the string.Thank, red_dwarfer_2002@yahoo.co.uk

Reply With Quote
  #2  
Old April 12th, 2004, 12:39 AM
fisch fisch is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 5 fisch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Not sure if this will help it's C++ code

string temp="To be or not to be: the question is illogical, Captain".
int length;
int index =0;
char findchar='e';

length = temp.size();//gets number of character in string;

loop for length(for or while loop)
if (temp[index]==findchar)
//will be true if character at position index is the same as the //character your looking for.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > C++ Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway