Well to signal an EOF condition in your terminal, you should press ctrl-z (if you're on windows), or ctrl-d (Linux or other BSD/Unix like operating systems).


Also, never use gets()
FAQ > Why gets() is bad / Buffer Overflows - Cprogramming.com