求救各位高手,帮我检查一下这个程序.很急的.谢谢哈!

flycatjing 2005-03-01 06:24:16
题目:统计一个文本文件的字母,数字,空格,以及其他字符的个数,并用条形图显示出它们的个数.
以下这个程序我已经运行过检查不出错,但的不到结果.请帮我改以下.尽量用简单的语句哈,我是初学者.

#include "stdio.h"
#include "graphics.h"
main()
{
int xx=200,yy=150;
FILE *fp;
char ch;
char jing[50];
int num1=0,num2=0,num3=0,other=0;
int gm,gd;
fp=fopen("文件名"," r ");
initgraph(&gd,&gm,"");
while ((ch=fgetc(fp))!=EOF)
{
if ((ch>='a'&&ch<='z')|| (ch>='A'&&ch<='Z') )
num1++;
else if (ch>='0'&&ch<='9')
num2++;
else if(ch=='')
num3++;
else
other++;
printf("letteris%d,digit is%d,space is%d,other is%d\n",num1,num2,num3,other);
fclose(fp);
}
setcolor(15);
rectangle(xx,yy,xx+num1*10,yy+10);
rectangle(xx,yy+20,xx+num2*10,yy+30);
rectangle(xx,yy+40,xx+num3*10,yy+50);
rectangle(xx,yy+60,xx+other*10,yy+70);
closegraph();
}
...全文
149 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
flycatjing 2005-03-02
  • 打赏
  • 举报
回复
还是不行呀!
shilei831115 2005-03-01
  • 打赏
  • 举报
回复
up!!
冷月清晖 2005-03-01
  • 打赏
  • 举报
回复
看错了
int gd=DETECT,gm;
冷月清晖 2005-03-01
  • 打赏
  • 举报
回复
int gm=DETECT,gd;
试试
xierlovexier 2005-03-01
  • 打赏
  • 举报
回复
up
flycatjing 2005-03-01
  • 打赏
  • 举报
回复
可不可以具体帮我该该哈.谢谢各位了
flycatjing 2005-03-01
  • 打赏
  • 举报
回复
谢谢你的回复,但我觉的好象没什么改动.运行不对.
dongyuanzhang 2005-03-01
  • 打赏
  • 举报
回复
应该先看你的打印语句打印了没有?

然后逐渐缩小范围,多写点打印语句跟踪!
冷月清晖 2005-03-01
  • 打赏
  • 举报
回复
#include "stdio.h"
#include "graphics.h"
main()
{
int xx=200,yy=150;
FILE *fp;
char ch;
char jing[50];
int num1=0,num2=0,num3=0,other=0;
int gm,gd; // 是不是这里没初始化啊????
fp=fopen("文件名"," r ");
initgraph(&gd,&gm,"");
while ((ch=fgetc(fp))!=EOF)
{
if ((ch>='a'&&ch<='z')|| (ch>='A'&&ch<='Z') )
num1++;
else if (ch>='0'&&ch<='9')
num2++;
else if(ch=='')
num3++;
else
other++;
printf("letteris%d,digit is%d,space is%d,other is%d\n",num1,num2,num3,other);
fclose(fp);
}
setcolor(15);
rectangle(xx,yy,xx+num1*10,yy+10);
rectangle(xx,yy+20,xx+num2*10,yy+30);
rectangle(xx,yy+40,xx+num3*10,yy+50);
rectangle(xx,yy+60,xx+other*10,yy+70);
closegraph();
}
kobefly 2005-03-01
  • 打赏
  • 举报
回复
你得程序应该是在tc下得,可我没有,没法帮你调试
#include "stdio.h"
#include "graphics.h"
main()
{
int xx=200,yy=150;
FILE *fp;
char ch;
char jing[50];
int num1=0,num2=0,num3=0,other=0;
int gm,gd;
fp=fopen("文件名"," r ");//这里应该改成你自己需要打开得文件名!
initgraph(&gd,&gm,"");
while ((ch=fgetc(fp))!=EOF)
{
if ((ch>='a'&&ch<='z')|| (ch>='A'&&ch<='Z') )
num1++;
else if (ch>='0'&&ch<='9')
num2++;
else if(ch=='')
num3++;
else
other++;
printf("letteris%d,digit is%d,space is%d,other is%d\n",num1,num2,num3,other);
fclose(fp);
}
setcolor(15);
rectangle(xx,yy,xx+num1*10,yy+10);
rectangle(xx,yy+20,xx+num2*10,yy+30);
rectangle(xx,yy+40,xx+num3*10,yy+50);
rectangle(xx,yy+60,xx+other*10,yy+70);
closegraph();
}

70,037

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧