怀化五中最漂亮的:帮忙看程序,急!!

来源:百度文库 编辑:神马品牌网 时间:2024/05/03 02:44:09
#include<stdio.h>
#include<stdlib.h>
void main()
{ char i;char ch; long temp=0;
FILE*fp;
if(( fp=fopen("e:\\baiyi.txt","r"))==0)
{ printf("文件打不开");exit(0);}

ch=fgetc(fp);

while(ch!=EOF)
{
ch=fgetc(fp);
temp++;
}
printf("输出文件长度%ld\n",temp);

ch=fgetc(fp);

for( i=32;i<=122;i++)
{
int count=0;
while(ch!=EOF)
{
ch=fgetc(fp);
if(i==ch)
{
count++;
}
printf("输出字符%c在文章中出现的概率%f",i,count/(1.0*temp));
}
}
}

程序后半部分为什么不行?运行结果为什么只有:输出文件长度。下面的概率就没有输出来?急!请高手指点!

printf("输出文件长度%ld\n",temp);

ch=fgetc(fp);
这个之间加个rewind(fp);把文件指针指到开头

上面是正解