比较两个字符串查找相同的子串
展开全部
#include <stdio.h>
bool isCharInSet(char c, char *set)
{
return (*set) ? ((c == *set) ? true : isCharInSet(c, set+1)) : false;
}
void main()
{
char *p0, s0[BUFSIZ] = {0};
char *p1, s1[BUFSIZ], s2[BUFSIZ];
printf("Input the 1st string: ");
scanf_s("%s", s1, BUFSIZ);
printf("Input the 1st string: ");
scanf_s("%s", s2, BUFSIZ);
p0 = s0;
p1 = s1;
while (*p1)
{
if (isCharInSet(*p1, s2) && !isCharInSet(*p1, s0))
{
*p0++ = *p1;
}
*p1++;
}
printf("The intersection of both strings is %s\n", s0);
scanf_s("%c", s0);
getchar();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询