gets()
reads always from standard input (stdin
)
fgets()
can read from an input stream (e.g. a file you open explicitly)
So, gets()
is equal to fgets()
with third parameter as stdin
.
At last, scanf()
can read formatted input data, parse it and set values to pointers you give.
Never use gets()
. It offers no protections against a buffer overflow vulnerability.
Avoid using scanf()
. If not used carefully, it can have the same buffer overflow problems as gets()
.
You should use fgets()
instead, although it's sometimes inconvenient.