search.c (509B)
1 /* Exercise 8.16 */ 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[BUF / 2], *searchPtr; 11 12 printf("Give me a string: "); 13 gets(string); 14 15 printf("Give me your search string: "); 16 gets(search); 17 18 searchPtr = strstr(string, search); /* Start the search */ 19 while( searchPtr != NULL ) { /* Found all next matches */ 20 printf("String: %s\n", searchPtr); 21 searchPtr = strstr(searchPtr + 1, search); 22 } 23 24 return 0; 25 } /* E0F main */ 26