0
Files in c
What ‘s the different between fgets and fscanf?
2 Respostas
+ 1
fgets reads a complete line of text into a string (a char array)
fscanf reads and searchs in formatted text different variables, like some numbers and characters that must be in a specific order
+ 1
fgets reads at most size characters from a file until it finds a newline and then it adds that newline to the string.
fscanf reads until it finds a space and then it stops and doesn't add a newline. If you read in a string with fscanf you can overrun the buffer which you cannot do with fgets (if you gave it the right size).
fscanf(fp, "%20s", str) to read in at most 20 char into string works too.