运行程序出错 求大侠指点~
编译无问题 运行出错提示如下Debug Assertion Failed!
Program:k:\Debug\1.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.
(press retry to debug the application)
程序如下:
#include <stdio.h>
#define MAX 200
int a[MAX],b[MAX],cnt=0;
void writeDat();
void jsVal()
{int i,j;
int a1,a2,a3,a4;
int temp;
for(i=0;i<200;i++)
{
a4=a[i]/1000;
a3=a[i]%1000/100;
a2=a[i] %100/10;
a1=a[i] %10;
if(a4%2!=0 && a3%2!=0 && a2%2!=0 && a1%2!=0)
{
b[cnt]=a[i];
cnt++;
}
}
for(i=0;i<cnt-1;i++)
for(j=i+1;j<cnt;j++)
if(b[i]<b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
}
}
void readDat()
{
int i;
FILE *fp;
fp=fopen("IN1.DAT","r");
for(i=0;i<MAX;i++)
fscanf(fp,"%d",&a[i]);
fclose(fp);
}
void main()
{
int i;
readDat();
jsVal();
printf("满足条件的数=%d\n",cnt);
for(i=0;i<cnt;i++)
printf("%d\n",b[i]);
printf("\n");
writeDat();
}
void writeDat()
{
FILE *fp;
int i;
fp=fopen("out1.dat","w");
fprintf(fp,"%d\n",cnt);
for(i=0;i<cnt;i++)
fprintf(fp,"%d\n",b[i]);
fclose(fp);
}
先谢过各位大侠了~~