char * strstr(char * str1, char * str2);
str1: C string to be scanned.
str2: C string containing the sequence of characters to match.
Function: locate substring.
Returns: a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1.
Example:
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="This is a simple string";
char * pch;
pch = strstr (str,"simple");
strncpy (pch,"sample",6);
puts (str);
return 0;
}
This example searches for the "simple" substring in str and replaces that word for "sample".
Output:
This is a sample string