#include <string.h>
#include <stdio.h>
#include <conio.h>
main()
{
char str1[20], str2[20], *p1, *p2;
int sum = 0;
printf("Please input two strings\n");
scanf("%s%s", str1, str2);
p1 = str1;p2 = str2;
while(*p1!='\0')
{
if(*p1 == *p2)
{
while(*p1 == *p2 && *p2 != '\0')
{
p1++;
printf("p1=%s\n", p1);
p2++;
printf("p2=%s\n", p2);
}
}
else
{
p1++;
}
if(*p2 == '\0')
{
sum++;
}
p2 = str2;
}
printf("%d", sum);
getch();
return 0;
}
C语言例子 计算字符串中子串出现的次数
最新推荐文章于 2024-04-25 21:59:26 发布