求顺序串的子串 C语言

来源:百度知道 编辑:UC知道 时间:2024/09/21 10:38:53
用C语言做的

#include "stdio.h"
#include "string.h"
#include "conio.h"
#define N 255
main()
{
char str1[N],str2[N],*p1,*p2;
int sum=0;
printf("\nPlease input two strings(<255 characters):\n");
scanf("%s%s",str1,str2);
p1=str1;
p2=str2;
while(*p1!='\0')
{
if(*p1==*p2)
{
while(*p1==*p2&&*p2!='\0')
{
p1++;
p2++;
}
}
else
p1++;
if(*p2=='\0')
sum++;
p2=str2;
}
printf("The result is %d",sum);
getch();
}