Assertion Failure???
Please support our C++ advertiser: Programming Forums
![]() |
•
•
Posts: 3
Reputation:
Solved Threads: 0
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?
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?
cplusplus Syntax (Toggle Plain Text)
#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; }
Last edited by Narue : Dec 10th, 2008 at 8:05 am. Reason: added code tags
>Expression: stream != NULL
Yet more proof (as if we needed any) that checking for success is a good thing. perror is your friend, my friend:
Yet more proof (as if we needed any) that checking for success is a good thing. perror is your friend, my friend:
cplusplus Syntax (Toggle Plain Text)
fp = fopen ( filename, "r" ); if ( fp == NULL ) { perror ( "Error opening file" ); exit ( EXIT_FAILURE ); }
I'm here to prove you wrong.
•
•
Posts: 3
Reputation:
Solved Threads: 0
thank you.Now the program is running but it doesn't work correct.Can you give me some advises how to do it.There is a file with numbers(one number per row) the program has to printf the average value of this numbers and how many times there is "6" between them.Thank you!
It must have 2 options.To write the information in file, or to printf on the screen!
It must have 2 options.To write the information in file, or to printf on the screen!
So what isn't working now?
The counting?
The average?
The output stream choice?
Here's a cookie
> float a,i;
What's i initialised to?
Then read the manual page on how to use printf, and what type %d is for.
The counting?
The average?
The output stream choice?
Here's a cookie
> float a,i;
What's i initialised to?
Then read the manual page on how to use printf, and what type %d is for.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
UK Voter? Please send a message to Incapability Brown and the rest of Zanu-Labour
Up to 8Mb PlusNet broadband from only £5.99 a month!
UK Voter? Please send a message to Incapability Brown and the rest of Zanu-Labour
Up to 8Mb PlusNet broadband from only £5.99 a month!
Right-click on the left margin at the first line in main(), and insert break point.
Then do run->debug program.
Then hover over the { } icons which appear to figure out which is "step into", "step over", "step out" etc.
Use these to step through your code one line at a time.
At every step, examine your variables to see if they contain what you expect.
When actuality != expectation, that's a BUG.
Then do run->debug program.
Then hover over the { } icons which appear to figure out which is "step into", "step over", "step out" etc.
Use these to step through your code one line at a time.
At every step, examine your variables to see if they contain what you expect.
When actuality != expectation, that's a BUG.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
UK Voter? Please send a message to Incapability Brown and the rest of Zanu-Labour
Up to 8Mb PlusNet broadband from only £5.99 a month!
UK Voter? Please send a message to Incapability Brown and the rest of Zanu-Labour
Up to 8Mb PlusNet broadband from only £5.99 a month!
![]() |
Similar Threads
Other Threads in the C++ Forum
- Debug Assertion Failure (C++)
- Help, Assertion Problem :(( (C++)
- Help, Assertion problem!!! :( (Visual Basic 4 / 5 / 6)
- Assertion Failed (C++)
- Debug Assertion Failure (Web Browsers)
- Assertion failure in loading (C++)
- Assertion Failure? (C++)
Other Threads in the C++ Forum
- Previous Thread: Get path to file found by FindFirstFile
- Next Thread: Win32API Movefile() Pathname problem
•
•
•
•
Views: 664 | Replies: 6 | Currently Viewing: 1 (0 members and 1 guests)






Linear Mode