Difference between fgets and fscanf?

The function fgets read until a newline (and also stores it). fscanf with the %s specifier reads until any blank space and doesn’t store it…

As a side note, you’re not specifying the size of the buffer in scanf and it’s unsafe. Try:

fscanf(ptr, "%9s", str)

Leave a Comment