| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > C++ Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|