June 22nd, 2003, 06:17 AM
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.
June 22nd, 2003, 08:38 AM
> char *pntr
You need to add a semi-colon to the end of that line. The clue is here:
> syntax error before 'FILE'
> #include <strings.h>
shouldn't this be <string.h>?
Last edited by BigBadBob; June 22nd, 2003 at 08:42 AM.
June 22nd, 2003, 09:23 AM
Ok thanks for that, those were silly little things as I thought.
Reword but still get some problems when compiling, these are two warnings. Anyone care to explain:
new.c(25) : warning C4047: '!=' : 'char *' differs in levels of indirection from
'const int '
new.c(32) : warning C4715: 'main' : not all control paths return a value
oh and I get an error when running this. Think its something to do with when I reach the end of the file.
using visual studio cl compiler this time for quickness, last time I used cc.