View Single Post
Join Date: Dec 2008
Posts: 3
Reputation: ogi1989 is an unknown quantity at this point 
Solved Threads: 0
ogi1989 ogi1989 is offline Offline
Newbie Poster

Assertion Failure???

 
0
  #1
Dec 10th, 2008
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?
  1. #include <conio.h>
  2.  
  3. int Artm(char *filename);
  4. int Count(char *filename);
  5.  
  6. int main()
  7. {
  8. char filename[81]="D:\\Test\\sign.txt";
  9. Artm(filename);
  10. Count(filename);
  11. return 0;
  12. }
  13.  
  14. int Artm(char *filename)
  15. {
  16. FILE *fp;
  17. float sr,a,i;
  18. char out[81]="\0";
  19. FILE *fout;
  20.  
  21.  
  22. fp=fopen(filename,"r");
  23. while(fscanf(fp,"%f",&a)!=-1)
  24. {
  25. sr+=a;
  26. i++;
  27. }
  28. sr=sr/i;
  29. printf("Save to:\1.file\n2.screen");
  30. scanf("%f",&a);
  31. switch(int(a))
  32. {
  33. case 1: printf("Filename ?\n");
  34. scanf("%s",out);
  35. fout=fopen(out,"w");
  36. fprintf(fout,"%f",sr);
  37. fclose(fout);
  38. break;
  39. case 2: printf("%f",sr);
  40. break;
  41. default: printf("1 or 2!");
  42. }
  43. fclose(fp);
  44. return 0;
  45. }
  46.  
  47. int Count(char *filename)
  48. {
  49. FILE *fp;
  50. float a,i;
  51.  
  52. fp=fopen(filename,"r");
  53. while(fscanf(fp,"%f",&a)!=-1)
  54. if(a==6)
  55. i++;
  56. printf("Count:%d",i);
  57. fclose(fp);
  58. return 0;
  59. }
Last edited by Narue; Dec 10th, 2008 at 9:05 am. Reason: added code tags
Reply With Quote