输入一个字符串,计算字符串中子串出现的次数
#include <stdio.h>
#include <string.h>
int count(char *str,char *str1)
{
int i;
int j;
int len;
i = 0;
j = 0;
len = 0;
while(str[i] != '\0')
{
if(str[i] != str1[j])
{
i++;
}
else
{
while(j < strlen(str1))
{
if(str[i] = str1[j])
{
j++;
i++;
}
else
{
break;
}
}
if(j = strlen(str1))
{
len++;
j = 0;
}
else
{
j = 0;
}
}
}
return len;
}
int main()
{
char str[30];
char str1[20];
int m;
printf("input the string!\n");
scanf("%s",str);
printf("input the small string!\n");
scanf("%s",str1);
m = count(str,str1);
printf("the number of string is %d\n",m);
return 0;
}
#include <stdio.h>
#include <string.h>
int count(char *str,char *str1)
{
int i;
int j;
int len;
i = 0;
j = 0;
len = 0;
while(str[i] != '\0')
{
if(str[i] != str1[j])
{
i++;
}
else
{
while(j < strlen(str1))
{
if(str[i] = str1[j])
{
j++;
i++;
}
else
{
break;
}
}
if(j = strlen(str1))
{
len++;
j = 0;
}
else
{
j = 0;
}
}
}
return len;
}
int main()
{
char str[30];
char str1[20];
int m;
printf("input the string!\n");
scanf("%s",str);
printf("input the small string!\n");
scanf("%s",str1);
m = count(str,str1);
printf("the number of string is %d\n",m);
return 0;
}