永发信息网

"编程统计一个文本文件 f.txt中所有字母和所有数字的总的出现次数。"

答案:2  悬赏:70  手机版
解决时间 2021-03-04 04:18
  • 提问者网友:一抹荒凉废墟
  • 2021-03-04 01:25
"编程统计一个文本文件 f.txt中所有字母和所有数字的总的出现次数。"这样一问题,我的答案是:#include"stdio.h"
#include"stdlib.h"
main()
{ FILE *fp;
char ch;
int i=0,j=0;
if((fp=fopen("D:\f.txt","r"))==NULL)
{
printf("cannot open the file\n");
exit(0);
}
ch=fgetc(fp);
while(ch!=EOF)
{
while(ch>'a'&&ch<'z'||ch>'A'&&ch<'Z')
i++;
while(ch<='9'&&ch>='0')
j++;
ch=fgetc(fp);
}
fclose(fp);
printf("There are %d zimu %d shuzi in the f.txt",i,j);
getch();
}
查询也没问题!但就是运行时,答案显示不出来!!一闪而过!!
最佳答案
  • 五星知识达人网友:几近狂妄
  • 2021-03-04 02:50
#include"stdio.h"
#include"stdlib.h"
main()
{ FILE *fp;
char ch;
int i=0,j=0;
if((fp=fopen("D:\\f.txt","r"))==NULL)
{
printf("cannot open the file\n");
exit(0);
}
ch=fgetc(fp);
while(ch!=EOF)
{
if(ch>'a'&&ch<'z'||ch>'A'&&ch<'Z')
i++;
if(ch<='9'&&ch>='0')
j++;
ch=fgetc(fp);
}
fclose(fp);
printf("There are %d zimu %d shuzi in the f.txt",i,j);
getch();
}
全部回答
  • 1楼网友:西岸风
  • 2021-03-04 03:15
:#include"stdio.h"#include"stdlib.h" main(){ file *fp; char ch; int i=0,j=0; if((fp=fopen("d:\f.txt","r"))==null) { printf("cannot open the file\n"); exit(0); } ch=fgetc(fp); while(ch!=eof) { while(ch>'a'&&ch<'z'||ch>'a'&&ch<'z') i++; while(ch<='9'&&ch>='0') j++; ch=fgetc(fp); } fclose(fp); printf("there are %d zimu %d shuzi in the f.txt",i,j); getch();}查询也没问题!但就是运行时,答案显示不出来!!一闪而过!!
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯