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算法更好一些。源码修罗开源源码
以下是源码绝地反击源码原版源码:*/
/*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-23 08:08
2024-11-23 07:37
2024-11-23 07:14
2024-11-23 07:12
2024-11-23 07:07
2024-11-23 06:58
2024-11-23 06:36
2024-11-23 05:58