+ 2
The difference between fgets and fgetc
What’s the difference between fgets and fgetc in c ? And when should I use each one ?
2 Antworten
+ 4
Kawtar
fgetc() is used to obtain input from a file single character at a time 'so it's returns an int'. while the fgets() function in C reads up to n characters from the stream (file stream or standard input stream) to a string. 'returns char pointer '
Each time you read (either via fgetc or fgets) you are making a system call which takes time, you want to minimize the number of times that happens, so calling fgets fewer times and iterating in memory is faster
+ 2
fgets() will read the whole string upto the size specified in argument list but when end of line occurs fgetc() returns EOF while fgets() returns NULL