gets will read from stdin until it finds a newline. You are leaving a newline there from previous operations, so it reads that in straightaway without you having to put any new data into the input buffer.
If you compile your code using g++, you even get warned about how bad gets is:
warning: the `gets' function is dangerous and should not be used.
It's important anyway: a user could enter EOF from keyboard and get this program stuck in an endless loop (although abusing gets() to read OP's passwords would be a more profitable use of the input access)
@ne555 I meant that in response to @ankit2313's "why did u use EOF [...] just !='\n' is sufficient" but yes, I was thinking C++ for a bit there. getchar()'ing a EOF'd stdin does not always return immediately (like cin.get()'ting a eof'd cin) : the outcome depends on the OS and probably terminal settings.
Without the EOF check, it loops forever on my Solaris, but reads the following characters on my AIX or Linux.
The program works perfectly well , thanks to you Moschops ,but I have couple of questions:
the first one is : I have a hard time to understand the relation between the while loop and gets() ,
I think the while loop dose not ends until It gets a caractere different than '\n' or EOF,then gets the name , am I right?