June 22nd, 2003, 06:17 AM
Join Date: Jun 2003
Time spent in forums: 9 h 40 m 14 sec
Reputation Power: 11
Reading files using Fgets, strange errors on compile.
I am trying to write a program to open a file, read the file line by line, and display the contents after the = sign on screen.
I am having problems, however, here is the code I am using:
/* Get pointer */
/* Open file */
input_file_pointer = fopen("clist.cfg","r");
/* if file is not present then stop */
if (input_file_pointer == NULL)
/* read in line by line and print on screen what is after the = sign */
while (fgets(word, 50, input_file_pointer) != EOF)
pntr = strchr(word, '=');
when I compile the program I get these errors:
syntax error before 'FILE'
new.c:14 'input_file_pointer' undeclared (first use in this function)
new.c:25 warning:comparison between pointer and integer
new.c:27 'pntr' undeclared (first use in this function)
Now I can open the file, and close the file. Somehow adding the while loop with fgets messes things up a little, its prolly quite easy but its starting to bug the hell outta me.
Any help is greatly appreciated guys.