fgets() syntax question

I looked on the reference page here and found that fgets() needs three parameters.
Here is a part of the code that I am doing.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main(){
	// declarations
	FILE *qFile;
	char bLine[100];
	// open file and read first line
	qFile = fopen("L:\\airmar.txt", "r");
	// store first line as char array in "bLine"
	fgets(bLine, 100, qFile);
	printf(bLine, "\n");

I am opening a text file that has lines of weather data.
$WIMDA,27.2739,I,0.9236,B,28.9,C,,,,,,,,,,,,,,*37
$WIMWD,,,,,,,,*40
$WIMWV,,T,,,V*7C
$WIMWV,291.0,R,0.8,N,A*21
$TIROT,-23.4,A*23
$WIMWV,291.9,R,0.8,N,A*28
$TIROT,-29.3,A*2E
$GPGGA,,,,,,0,,,,,,,,*66

Every time I try to run this, I get a run time error:
Expression (str != NULL)
and it shows me fgets.c and points to the following line: 57
_VALIDATE_RETURN(( str != NULL ), EINVAL, NULL);
What am I doing wrong in terms of syntax?
Thanks.
Last edited on
The code you posted looks ok. But you clearly have some serious error, maybe a memory overwrite or something.

And you seem to have trouble processing that input file as you've tried C++ streams and now C files.

Perhaps if you posted more of the program we might be able to offer some useful tips. Whatever your problem is, I don't think you're asking the right questions.
Topic archived. No new replies allowed.