Name
strstr - Finds a string in a string.
Syntax
#include <string.h>
char *strstr(string1, string2)
const char *string1;
const char *string2;
Description
The strstr function returns a pointer to the first
occurrence of string2 in string1.
Return Value
The strstr function returns either a pointer to the first
occurrence of string2 in string1, or NULL if it does not
find string2 in string1.
See Also
strcspn(DOS)
Example
#include <string.h> #include <stdio.h>
main()
{
char *string1 = "needle in a haystack";
char *string2 = "hay";
printf("%s\n", strstr(string1,string2));
}
Output:
haystack
This program uses strstr to return a pointer to the first
location of hay in the string string1, then prints the
remainder of the string.
(printed 6/18/89)