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效率高吗?源码有谁知道的
/*解决一般长度的可以。。源码查看python源码手机因为使用了朴素的源码自动化测试App源码字符串匹配算法,所以效率不算高,源码量化导弹副图指标源码KMP算法更好一些。源码赛赛体育直播app源码
以下是源码制作抗击疫情网站源码源码:*/
/*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:32
2024-11-20 00:02
2024-11-19 22:56
2024-11-19 22:51
2024-11-19 22:19