#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int strstr(char *str, char*pch,int size,int size1){
char *p = str;
while (1){
int i = 0;
int j = 0;
for (; i < size - 1; i++){
if (str[i] == pch[j]){
j++;
if (pch[j] == '\0'){
return p;//返回str中第一处pch字符串的位置
}
}
else{
p = str + i;
j = 0;
}
}
p = NULL;
return p;
}
}
int main(){
char str[] = "this is a simple string";
int size = sizeof(str);
char pch[] = "sime";
int size1 = sizeof(pch);
char* p=strstr(str, pch, size, size1);
printf("%s", p);//若找到则从第一处pch字符串的位置打印str.没找到则打印空字符串
system("pause");
return 0;
}