/* File: count.c A simple recursive function to compute the the number of times a character appears in a string. */ #include #include int count(char c, char *str, int low, int high) { if (high < low) return 0 ; if (str[high] == c) { return 1 + count(c, str, low, high-1) ; } else { return count(c, str, low, high-1) ; } } main(){ char c, *str = "senselessness" ; int n, m ; m = strlen(str) - 1 ; c = 's' ; n = count(c, str, 0, m) ; printf ("'%c' appeared %d times\n", c, n) ; c = 'e' ; n = count(c, str, 0, m) ; printf ("'%c' appeared %d times\n", c, n) ; c = 'n' ; n = count(c, str, 0, m) ; printf ("'%c' appeared %d times\n", c, n) ; }