fflush(3) is documented as working on output streams, not on input ones.
The standards do not specify the behavior for input streams.
In particular POSIX specification for fflush don't mention input streams.
So it is probably an undefined behavior from the POSIX point of view.
However, on Linux fflush(stdin)
is possible (but I don't recommend it) since
For input streams associated with seekable files (e.g., disk files,
but not pipes or terminals), fflush()
discards any buffered data that
has been fetched from the underlying file, but has not been consumed
by the application.
For input streams, fflush() discards any
buffered data that has been fetched from the underlying file, but has
not been consumed by the application.
(notice the mention of a seekable file ; usually your stdin
is a terminal which is not a genuine disk file, and lseek(2) would fail on the terminal)
BTW, gets(3) is deprecated because dangerous (possible buffer overflow!) and has disappeared from C11 standard. Use at least fgets(3) and preferably getline(3) instead. Perhaps consider GNU readline library (which offers nice editing abilities).