The sample program is probably not a good idea to study -

It uses fflush(stdin)
FAQ > Why fflush(stdin) is wrong - Cprogramming.com

and gets()
FAQ > Why gets() is bad / Buffer Overflows -...