There are a ton of things wrong with your code:

1) Never flush stdin or any stream for that matter. That behavior is undefined. Beginners use fflush way to happily.

2) Don't loop around feof()....