lot many programmers and C programming books says about using fflush(stdin) to clear the input buffer.. Unfortunately its not correct.. You should not use fflush on stdin buffer.
Lets look at the definition of fflush():
fflush - flush a stream
int fflush(FILE *stream);
For output streams, fflush() forces a write
of all user-space buffered data for the given output
or update stream via the stream's underlying write function.
For input streams, fflush() discards any buffered data
that has been fetched from the underlying file, but
has not been consumed by the application.
The open status of the stream is unaffected.
If the stream argument is NULL, fflush() flushes
all open output streams.
Its defined for output streams.. According to the standard, in posix system if you use fflush(stdin) you are into "undefined behavior" ..