1.strstr Դ?源码?
2.c语言的查找字符串函数strstr效率高吗?源码有谁知道的
strstr Դ??
int strcmp(char *s,char *t){
while(*s==*t&&*s){ s++;t++;}
return *s-*t;
}
char *strcat(char *s,char *t)
{
char *p=s;
while(*p) p++;
while(*p++=*t++)
return s;
}
char *strstr(char *s,char *t)
{
char *p1,*p2;
while(*s)
{
for(p1=s,p2=t;*p1==*p2&&*p2;p1++,p2++);
if(*p2=='\0') return(s);
s++;
}
return NULL;
}
c语言的查找字符串函数strstr效率高吗?源码有谁知道的
/*解决一般长度的可以。。源码gh电池源码因为使用了朴素的源码疯狂火箭源码字符串匹配算法,所以效率不算高,源码短文小说源码KMP算法更好一些。源码杭州wordpress源码
以下是源码4源码树源码:*/
/*strstr function*/
#include<string.h>
char *(strstr)(const char *s1, const char *s2)
{ /* find first occurrence of s2[] in s1[] */
if (*s2 == '\0')
return ((char*)s1);
for (; (s1 = strchr(s1, *s2)) != NULL; ++s1){ /*match rest of prefix*/
const char *sc1, *sc2;
for (sc1 = s1, sc2 = s2;;)
if (*++sc2 == '\0')
return ((char *)s1);
else if (*++sc1 != *sc2)
break;
}
return (NULL);
}
/*strchr function*/
#include<string.h>
char *(strchr)(const char *s, int c)
{ /* find first occurrence of c in char s[] */
const char ch = c;
for (; *s != ch; ++s)
if (*s == '\0')
return (NULL);
return ((char*) s);
}
2024-11-20 00:13
2024-11-20 00:10
2024-11-20 00:08
2024-11-19 23:30
2024-11-19 23:22
2024-11-19 22:50
2024-11-19 22:02
2024-11-19 21:51