#include <stdio.h>
char *strstr(char *str, char *chs){
char *temp_str = str; // 用于记录遍历到str的哪个位置,方便遍历和返回
while (*temp_str != 0)
{
char *p_chs = chs;
char *p_str = temp_str;
while ((*p_str == *p_chs) && (*p_chs != '\0'))
{
p_str++;
p_chs++;
}
if (*p_chs == '\0')
{
printf("temp_str == %s\n", temp_str);
return temp_str;
}
else
{
temp_str++;;
}
}
}
int main(){
char str[] = "helloworld";
char * chs = "llo";
char * p = strstr(str, chs);
printf("p == == = %s\n", p);
system("pause");
return 0;
}
自己亲手操练strstr
最新推荐文章于 2024-05-14 15:34:27 发布