您的位置:首页 > 其它

小作业(一个字符串中包含几个另一个字符串)

2014-10-30 08:56 85 查看
#include <stdio.h>
#include <string.h>

#define Num 1000

int main()
{
int i = 0,j = 0,k,count = 0,h = 0,c;
char str1[Num],str2[Num],str3[Num];

printf("Please input the first string,and enter as the end:\n");

while((c = getchar()) != EOF && c != '\n')

{
str1[i] = c;
i++;
}

printf("Please input the second string,and enter as the end:\n");

while((c = getchar()) != EOF && c != '\n')
{
str2[j] = c;
j++;
}

if(i < j)
{
printf("str1 has 0 str2");
}

else
{
for(k = 0;k < i - j + 1;k++)
{
for(h = 0;h < j;h++)
{
str3[h] = str1[k + h];
}

if(strcmp(str3,str2) == 0)
count++;
}
printf("str1 has %d str2s",count);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: