实现strstr函数

来源:互联网 发布:什么叫做js事件event 编辑:程序博客网 时间:2024/05/16 17:20

新手自己实现的strstr函数,,不足之处请指教

#include<stdio.h>char *mystrstr(char *str1, char *str2){    while (*str1 != '\0')    {        char *nowstr1 = str1;        char *nowstr2 = str2;        while (*nowstr1 == *nowstr2)        {            nowstr1++;            nowstr2++;            if (*nowstr2 == '\0')            {                return str1;            }        }        str1++;    }           return NULL;}void main(){    char str1[100]="wohenaini";    char str2[100]="ai";    char *findd = mystrstr(str1, str2);    if (findd == NULL)    {        printf("没有找到字符串\n");    }    else    {        printf("找到!!\n");        printf("%s\n", findd); //返回字符串    }}
0 0
原创粉丝点击