/*
主题:字符串中子串的查找
*/
#include <stdio.h>
#include <assert.h>
//循环取src的子串与sub比较
const char *strstr(const char*src, const char *sub)
{
const char *bp;
const char *sp;
if (src == NULL || sub == NULL)
{
return src;
}
while(*src)
{
bp = src;
sp = sub;
do
{
if (!*sp)
{
return src;
}
} while (*bp++ == *sp++);
src += 1;
}
return NULL;
}
int main(void)
{
char p[] = "12345";
char q[] = "34";
const char *r = strstr(p, q);
printf("r: %s\n", r);
return 0;
}
字符串中子串的查找
最新推荐文章于 2022-07-01 19:56:37 发布