C examples for string.h:strstr
function
<cstring> <string.h>
Returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1.
const char * strstr ( const char * str1, const char * str2 ); char * strstr ( char * str1, const char * str2 );
Parameter | Description |
---|---|
str1 | C string to be scanned. |
str2 | C string containing the sequence of characters to match. |
A pointer to the first occurrence in str1 of the entire sequence of characters specified in str2
A null pointer if the sequence is not present in str1.
#include <stdio.h> #include <string.h> int main ()/*w w w . j a v a 2 s. c o m*/ { char str[] ="This is a simple string"; char * pch; pch = strstr (str,"simple"); strncpy (pch,"sample",6); puts (str); return 0; }