本程序将查找字符串s和字符串l中是否含有子字符串1,并对目字符串中找到的从子字符串开始的所有字符输出。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <alloc.h>
int main(void)
{
char *s="Golden Global View"; //母串
char *l="lob"; //子串
printf("string s is :%s\n",s);
printf("substr l is :%s\n",l);
printf("seek result:\n");
char *p;
p=strstr(s,l); //在母串s中查找子串l的位置,返回查找结果对应的指针
if(p) //如果找到
printf("%s\n",p); //显示该位置之后的字符串
else
printf("Not Found!\n");
system("pause");
return 0;
}