searchc.c (509B)
1 /* Exercise 8.18 */ 2 3 #include <stdio.h> 4 #include <string.h> 5 6 #define BUF 254 7 8 int main(void) 9 { 10 char string[BUF], search, *searchPtr; 11 12 printf("Give me a string: "); 13 gets(string); 14 15 printf("Give me your search character: "); 16 search = getchar(); 17 18 searchPtr = strchr(string, search); /* Start the search */ 19 while( searchPtr != NULL ) { /* Found all next matches */ 20 printf("String: %s\n", searchPtr); 21 searchPtr = strchr(searchPtr + 1, search); 22 } 23 24 return 0; 25 } /* E0F main */ 26