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

来源:互联网 发布:检测僵尸粉软件 编辑:程序博客网 时间:2024/05/16 08:11
#include <stdio.h>#include <string.h>#define Num 1000int 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;}

0 0