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

用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运行通过。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-05-21
#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]", word);

j = c = 0;
l1 = strlen(line), l2 = strlen(word);

for (i = 0; i < l1; ++i)
{
if(line[i] == word[j])
{
++j;
}
else
j = 0;

if (j == l2)
{
j = 0;
++c;
}
}

printf("%d\n", c);
getchar();
getchar();
}本回答被提问者采纳
第2个回答  2009-05-21
用string不行吗?
查找is,判断is前后字符是否为字母,若都不是,则计数器自增