函数原型:extern char *strstr(char *str1, char *str2);
功能:从字符串str1中查找是否有字符串str2,如果有,从str1中的str2位置起,返回str1的指针,如果没有,返回null。
include <stdio.h>
char* strstr(const char* s1, const char s2)
{
if(s1==NULL)
return NULL;
while (s1!=0)
{
int i = 0;
while(1)
{
if(s2[i]==0)
return s1;
if(s2[i]!=s1[i])
break;
i++;
}
s1++;
}
return NULL;
}
int main(int argc, const char * argv[]) {
// insert code here...
char str[] = "insert_code_here";
char* str1 = strstr(str,"de");
printf("%s", str1);
return 0;
}