I've read a lot that fgets if better to use instead of scanf. My question is what about using fscanf when reading a file? Is fscanf the only way to go when reading a file?
-Thnx
This is a discussion on fscanf within the C Programming forums, part of the General Programming Boards category; I've read a lot that fgets if better to use instead of scanf. My question is what about using fscanf ...
I've read a lot that fgets if better to use instead of scanf. My question is what about using fscanf when reading a file? Is fscanf the only way to go when reading a file?
-Thnx
personally for me it depends what I'm doing if I need an entire line I do fgets(stream name,variable,length) (or whatever the precise syntax is), but if I'm reading a text file for records with is like a string, integer, string I'll use fscanf coz its a bit easier and I've personally never had problems, just try them both and see what ya think works best for you I reacon.
OK, Thank you.
According to the man page on fgets() (Solaris 5.7)
char * fgets(char *s, int n, FILE *stream)
The fgets() function reads characters from the stream into
the array pointed to by s, until n-1 characters are read, or
a newline character is read and transferred to s, or an
end-of-file condition is encountered. The string is then
terminated with a null character.
...
DrakkenKorin
Get off my Intarweb!!!!
And for reading binary data from a file you use the fread function.
I used to be an adventurer like you... then I took an arrow to the knee.
Thank you all. They don't teach us how to use fgets in my C class.
I don't understand why. Once I learned how to read a line using fgets instead of scanf it seemed so much easier and scanf seems like a pain now. LOL!
-Thnx for the advice.