Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- recursive_function_to_count_occurences_of_ch_in_string_v1.c
- Using recursive function to count occurences of ch in string
- https://stackoverflow.com/questions/40888686/using-recursive-function-to-count-occurences-of-letters?fbclid=IwAR0MO7rGj7jw7dmBQDF2okDeJZpavzKnHTnNmkR0vv6RTgY-H_esbYJjR_I
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- int count_ch_in_string( char *source, char ch )
- {
- if(*source == '\0')
- return 0;
- if( *source == ch )
- return(1 + count_ch_in_string(++source, ch) );
- return( count_ch_in_string(++source, ch) );
- }
- int main(void)
- {
- char str[]="This is a string to test recursive function count_ch_in_string().";
- char ch='t';
- printf("\n In string: \n\n|%s| \n\n there are %d characters '%c' . \n\n",
- str, count_ch_in_string(str,ch), ch);
- return 0;
- } // main()
Add Comment
Please, Sign In to add comment