Syntax
#include <string.h> char *strstr(const char *string1, const char *string2);Description
strstr finds the first occurrence of string2 in string1. The function ignores the null byte (\0) that ends string2 in the matching process.
strstr returns a pointer to the beginning of the first occurrence of string2 in string1. If string2 does not appear in string1, strstr returns NULL. If string2 points to a string with zero length, strstr returns string1.
This example locates the string haystack in the string "needle in a haystack".
#include <string.h>
int main(void)
{
char *string1 = "needle in a haystack";
char *string2 = "haystack";
char *result;
result = strstr(string1, string2);
/* Result = a pointer to "haystack" */
printf("%s\n", result);
return 0;
/****************************************************************************
The output should be:
haystack
****************************************************************************/
}
Related Information