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效率高吗?源码有谁知道的
/*解决一般长度的可以。。源码网页在线通话源码因为使用了朴素的源码聚优网源码字符串匹配算法,所以效率不算高,源码跑分源码网KMP算法更好一些。源码挖鱼网源码网
以下是源码1的源码是源码:*/
/*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-19 23:31
2024-11-19 23:23
2024-11-19 23:22
2024-11-19 23:02
2024-11-19 21:45
2024-11-19 21:35
2024-11-19 21:18
2024-11-19 21:18