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.
#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;
}
(program is unfinished, but still should work).
Why is it giving me this?