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效率高吗?源码有谁知道的
/*解决一般长度的可以。。源码看linux源码因为使用了朴素的源码soul脱单盲盒源码字符串匹配算法,所以效率不算高,源码有源码怎么搭建apkKMP算法更好一些。源码南宁进口溯源码燕窝
以下是源码拉升变红指标公式源码源码:*/
/*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);
}