#include<stdio.h>
#include<string.h>
#define MAXSIZE 100
void main()
{
char str1[MAXSIZE];//用于存储字符串
char str2[MAXSIZE];
char *p1,*p2;//指针
int num=0;//用于统计子串的个数
printf("请输入字符串和子串:\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')
num++;
p2=str2;//重新使p2指向子字符串
}
printf("%d\n",num);
}
One-day-one-program(8)之统计字符串中子串的个数
最新推荐文章于 2022-02-07 01:37:02 发布