Function name : strstr
Header file : <string.h>
Function prototype : char *strstr(const char *destin, const char *str);
Function : Find the first occurrence of another string in a string
Parameters : const char *destin is the target string to be found
const char *str is the string to be found
Return value : Returns a pointer to the first occurrence of the matching string.
Program example: Find the first occurrence of the string str in the string destin, return the search result and output it
#include<string.h>#include<stdio.h>intmain(void){char*str1=Ilikewww.dotcpp.comverymuch!,*str2=www.dotcpp.com;char*ptr=strstr(str1,str2); printf(Thesubstringis:%sn,ptr);return0;}
Running results:
Thesubstringis:www.dotcpp.comverymuch!