c语言问题 高手帮忙下

来源:百度知道 编辑:UC知道 时间:2024/07/02 11:45:42
做一个程序,通过输入某个字符串,统计此字符串的个数,统计此文档所有字数
比如输入:“this is an apple" 统计"apple"字数,结果是一个。所有字数是4个。
楼下的你刚开始就错了
include 你少了个C
而且你的程序也运行不了
3楼说的很正确
请问你能帮忙下吗

楼主的题目不明确。
我估计他的目的是:
输入一个字符串,比如apple
然后从某个文件里面查找这个apple出现的次数,并统计这个文件里面有多少个单词。

不知道我理解的对不对。
查找的文本文件是D:\test.txt

#include <stdio.h>
#include <conio.h>
#include <string.h>
main()
{
int i;
int count=0;
int word=0;
char *input;
char *text;
FILE *fp;

fp=fopen("d:\\test.txt","r");
if (fp==NULL)
{
printf("File Open Error:\nPress any key to exit:");
getch();
exit(1);
}
printf("input a string for search:");
scanf("%s",input);

do
{
fscanf(fp,"%s",text);
word++;
if (strcmp(text,input)==0)
count++;
}while(!feof(fp));
printf("word=%d\nfind string:%s %d times\n",word,input,count);

getch();
}

#inlude <stdio.h>
void main(void)