/* File: strstr.c An example showing how to use strstr() from the string library. */ #include #include int main() { // String to search in char *long_string = "Here and there and everywhere." ; // String we are searching for char *short_string = "ere" ; // where short_string was found char *location ; // Look for the first match location = strstr(long_string, short_string) ; printf("Rest of the string = \"%s\"\n", location) ; // Look for the second match. // Note the use of location + 1 to specify the // location after the first match location = strstr(location+1, short_string) ; printf("Rest of the string = \"%s\"\n", location) ; // Look for the third match. location = strstr(location+1, short_string) ; printf("Rest of the string = \"%s\"\n", location) ; // Look for the fourth match. location = strstr(location+1, short_string) ; if (location == NULL) { printf("No fourth match found.\n") ; } return 0 ; }