标题:[求助]我的程序哪里错了
取消只看楼主
shenbingmeng
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-9-1
 问题点数:0 回复次数:1 
[求助]我的程序哪里错了
我想通过下面这个程序,实现从一个文本文件wenjian.txt中读取数据,并统计各个字符出现的概率,将结果保存在prob.txt中,各个字符是保存在string.txt中,如果可以的话,也可以将这两个数组一起保存在out.txt中。可是不知道为什么,一个是程序中数组定义不知道哪里出问题,二是程序中prob.txt中就是没有输出的内容,我也不知道是为什么?求助,请各位高手指导下:#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
# include<ctype.h>
#define N 43
int main( )
{
FILE *fp1,*fp2;
long i,count,sum=0;
char ch,m;
int num[N];
float prob[N];
char string[N]={'a','b','c','d','e','f','g','h','i',
'j','k','l','m','n','o','p','q','r','s','t','u','v',
'w','x','y','z',' ', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0','<','>',',','.''@','#'};
if((fp1=fopen("d:\\string.txt","w"))==NULL)
{
printf("cannot open this file.\n");
exit(0);
}
fwrite(string,sizeof(char),N,fp1);
if((fp2=fopen("d:\\wenjian.txt","r"))==NULL)
{
printf("cannot open this file.\n");
exit(0);
}
for(i=0;i<N;i++)
{
count=0;
ch=string[i];
while((m=fgetc(fp2))!=EOF)
{
if(isascii(m))
{
if(m==ch)
count++;
}
}
num[i]=count;
}
for(i=0;i<N;i++)
sum+=num[i];
for(i=0;i<N;i++)
prob[i]=num[i]/sum/1.00f;
fclose(fp1);
fp1=fopen("d:\\prob.txt","a+");
fwrite(prob,sizeof(char),N,fp1);
}
搜索更多相关主题的帖子: 统计 文本文件 include count 
2006-09-01 11:06
shenbingmeng
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-9-1
得分:0 

真是谢谢上面的几位高手,我明白了,非常感谢!

2006-09-01 15:18



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




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

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