The problem with fgets is that if the input exceeds the destination buffer size the remaining input remains in the keyboard buffer. If you make your destination buffer sufficiently large this would rarely, if ever, happen. But it still could happen. You could also do something like this:
Code:
fgets(buf, sizeof(buf), stdin);
if( strlen(buf)+1 == sizeof(buf) )
{
while ( (ch = getchar() ) != EOF && ch != '\n' );
}
which cleans up the keyboard buffer if the destination buffer length is exceeded.
[edit]
This is better:
Code:
fgets(buf, sizeof(buf), stdin);
if( strchr(buf, '\n') == NULL )
{
while ( (ch = getchar() ) != EOF && ch != '\n' );
}