标题:[求助]得不到结果啊??
取消只看楼主
TCL
Rank: 1
等 级:新手上路
威 望:1
帖 子:68
专家分:0
注 册:2006-3-28
 问题点数:0 回复次数:2 
[求助]得不到结果啊??


我写了关于文件里单词出现的次数,但是得不到结果!为什么呢??
源程序如下:
#include<stdio.h>
#include<string.h>

void main(int argc, char* argv[])
{ char word_1[10];
char word_2[10];
char ch;
int count;
FILE *fp;
if((fp=fopen("E:/file.txt","rt"))==NULL)
{ printf("cannot open the file\n");
return;}
printf("input the word:\n");
scanf("%s",word_2);
ch=fgetc(fp);
while(ch!=EOF)
{ int i=0;
while(ch!=' ')
{ word_1[i]=ch;
ch=fgetc(fp);
i++;}
word_1[i]='\0';
if((strlen(word_1)==strlen(word_2))&&(strcmp(word_1,word_2)==0))
count++;}
printf("%d",count);
fclose(fp);
}

搜索更多相关主题的帖子: 得不到 结果 
2006-05-10 17:04
TCL
Rank: 1
等 级:新手上路
威 望:1
帖 子:68
专家分:0
注 册:2006-3-28
得分:0 
都是一样没结果啊!!

我要为C语言努力!!!谁都不能挡我!!挡我者。。看你怎样活·····
2006-05-10 17:20
TCL
Rank: 1
等 级:新手上路
威 望:1
帖 子:68
专家分:0
注 册:2006-3-28
得分:0 
还需要怎样改啊 改不了的话就给老师 谢谢大哥们!!

我要为C语言努力!!!谁都不能挡我!!挡我者。。看你怎样活·····
2006-05-10 17:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-63179-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.056133 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved