I'm trying to read from a text file.I think that everything is correct!It gives me this error message:
Debug Assertion Failed!
Program: D:\Test\sign.exe
File: fscanf.c
Expression: stream != NULL
For information on how your program can cause assertion failure, see the Visual C++ documentation on asserts.
CAN SOMEONE HELP?
#include <conio.h>
int Artm(char *filename);
int Count(char *filename);
int main()
{
char filename[81]="D:\\Test\\sign.txt";
Artm(filename);
Count(filename);
return 0;
}
int Artm(char *filename)
{
FILE *fp;
float sr,a,i;
char out[81]="\0";
FILE *fout;
fp=fopen(filename,"r");
while(fscanf(fp,"%f",&a)!=-1)
{
sr+=a;
i++;
}
sr=sr/i;
printf("Save to:\1.file\n2.screen");
scanf("%f",&a);
switch(int(a))
{
case 1: printf("Filename ?\n");
scanf("%s",out);
fout=fopen(out,"w");
fprintf(fout,"%f",sr);
fclose(fout);
break;
case 2: printf("%f",sr);
break;
default: printf("1 or 2!");
}
fclose(fp);
return 0;
}
int Count(char *filename)
{
FILE *fp;
float a,i;
fp=fopen(filename,"r");
while(fscanf(fp,"%f",&a)!=-1)
if(a==6)
i++;
printf("Count:%d",i);
fclose(fp);
return 0;
}