| | |
Assertion Failure?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2005
Posts: 55
Reputation:
Solved Threads: 0
I'm trying to read from a text file. Pretty simple, right? I guess not. It gives me this error message:
Debug Assertion Failed!
Program: F:\Debug\lab1431.exe
File: fscanf.c
Expression: stream != NULL
For information on how your program can cause assertion failure, see the Visual C++ documentation on asserts.
(program is unfinished, but still should work).
Why is it giving me this?
Debug Assertion Failed!
Program: F:\Debug\lab1431.exe
File: fscanf.c
Expression: stream != NULL
For information on how your program can cause assertion failure, see the Visual C++ documentation on asserts.
C++ Syntax (Toggle Plain Text)
#include <stdio.h> #define FILENAME "F:/Debug/lab14data.txt" int main(void) { int num_data_pts = 0, fday, day = 1; double ffahr, max, min; FILE *temp_each_day; temp_each_day = fopen(FILENAME, "r"); if (temp_each_day = NULL) printf("Error opening input file. \n"); else { while (fscanf(temp_each_day,"%i %lf", &fday, &ffahr) == 2) { num_data_pts++; day++; printf(" Day Fahrenheit Celsius"); printf("%4i %7lf %7lf", fday, ffahr, (ffahr + 32) / 1.8); if (num_data_pts == 1) max = min = ffahr; else if (ffahr > max) max = ffahr; else if (ffahr < min) min = ffahr; } } return 0; }
Why is it giving me this?
if (temp_each_day = NULL)
printf("Error opening input file. \n"); Last edited by ~s.o.s~; Apr 8th, 2007 at 4:01 pm.
I don't accept change; I don't deserve to live.
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
since the debud assertion that fails is:
the error is that at a place where the
stream was expected to be NULL, it is not NULL. stream (in the FILE structure)
would be NULL after the file has been closed.
remember that fscanf can corrupt memory if your format specifiers are incorrect.
•
•
•
•
Debug Assertion Failed!
Program: F:\Debug\lab1431.exe
File: fscanf.c
Expression: stream != NULL
stream was expected to be NULL, it is not NULL. stream (in the FILE structure)
would be NULL after the file has been closed.
remember that fscanf can corrupt memory if your format specifiers are incorrect.
Last edited by vijayan121; Apr 8th, 2007 at 4:06 pm. Reason: formatting
•
•
Join Date: Jul 2005
Posts: 55
Reputation:
Solved Threads: 0
•
•
•
•
The = in the above code should be replaced by == if what you want to do is comparision.if (temp_each_day = NULL) printf("Error opening input file. \n");
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
•
•
•
•
The = in the above code should be replaced by == if what you want to do is comparision.if (temp_each_day = NULL) printf("Error opening input file. \n");
a. the if block will not execute.
b. fclose(NULL) will assert and an assertion wil fail on exit if fclose is not called.
Last edited by vijayan121; Apr 8th, 2007 at 4:11 pm. Reason: format
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
C++ Syntax (Toggle Plain Text)
if (temp_each_day = NULL)
tip: set the warning level of the compiler to the highest available, and pay attention to the warnings.
you would save yourself a great deal of effort and time.
Last edited by vijayan121; Apr 8th, 2007 at 4:21 pm. Reason: format
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: string array size
- Next Thread: compile error
| Thread Tools | Search this Thread |
api application 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 graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie 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 url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets







