c语言实现,统计一句英文句子中某个单词出现的次数。

来源:百度知道 编辑:UC知道 时间:2024/06/28 14:59:13
用WINTC编辑,实现功能如题。
例如
先输入一句话:what is your name? my name is lily.
再输入要统计的单词:is
结果要显示is出现的此数:2

各位帮帮忙~
拜托最好给出完整的程序~

#include<stdio.h>
int FindWord(char*,char*);
void main()
{
char allstr[100];
char findstr[20];
puts("input all word:");
gets(allstr);
puts("input one word:");
gets(findstr);
printf(" number of %s is :%d\n",findstr,FindWord(allstr,findstr));
}
int FindWord(char* allstr,char* findstr)
{
int wordnum = 0;
char* temp = findstr;
while(*allstr)
{
if(*allstr == *temp)
{
temp++;
if(*temp==NULL)//findstr is end
{
wordnum++;
temp = findstr;

}
}
allstr++;
}
return wordnum;
}

以上程序在VC6.0运行通过。

#include <stdio.h>
#include <string.h>

void main()
{
char line[100];
char word[20];
int i, j, l1, l2, c;

scanf("%100[^\n]", line);
getchar();
scanf("%20[^\n