| | |
Assertion Failure???
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
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?
C++ 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 9: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:
C++ 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.
•
•
Join Date: Dec 2008
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!
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.
![]() |
Similar Threads
- 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
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






