读入文件出错怎么回事?
程序调试都没出错,可是一运行就弹这个错误,要关闭。不知什么原因啊。就下面这个错误。in.dat在所在文件夹里。难道是in.dat数据格式错误,但是不会啊。
Debug Assertion Failed!
Program:E:\temp\aaaa\Debug\aaa.exe
file:fscanf.c
Line:54
expression:stream!=NULL
For information on how your program can cause an assertion failure,see the Visual C++ documentation on asserts.
下面是我的全部代码:
#include <stdio.h>
int a[300],cnt=0;
double pjz1=0.0,pjz2=0.0;
jsValue()
{int i,k,l,m,n,p=0;
for(i=0;i<300;i++)
{ k=a[i]/1000;
l=a[i]%1000/100;
m=a[i]%100/10;
n=a[i]%10;
if((k+n)==(l+m))
{cnt++;
pjz1+=a[i];
}
else {p++;pjz2+=a[i];}
}
pjz1/=cnt;
pjz2/=p;
}
main()
{
int i;
readDat();
jsValue();
writeDat();
printf("cnt=%d\n满足条件的平均值pzj1=%7.21f\n不满足条件的平均值pjz2=%7.21f\n" ,cnt,pjz1,pjz2);
}
readDat()
{
FILE *fp;
int i;
fp=fopen("in.dat" ," r" );
for( i=0;i<300;i++) fscanf(fp,"%d",&a[i]);
fclose(fp);
}
writeDat()
{
FILE *out;
int i;
out=fopen(" out.dat" ," w" );
fprintf(out," %d\n%7.21f\n%7.21f\n" ,cnt,pjz1,pjz2);
fclose(out);
}
[此贴子已经被作者于2006-7-23 1:50:29编辑过]