While loop asking for input until ctrl-d using C -


i want make while loop continually asking user input until user ctrl-d's out of it. how can correctly? using right now:

 while (1)     {         printf("enter host name: ");         fgets(user_input, 1000, stdin);     } 

this works, except user has hit ctrl-c end program. wanting continually ask user input until he/she hits ctrl-d. how can this?

you have test eof, ctrl-d returns.

so this:

while ( fgets( ... ) != null ) {     ... } 

edit:

since you're prompting, better be:

for ( ;; ) {     printf( "enter input: " );     fflush( null );   // make sure prompt displayed, credit basile starynkevitch     if ( fgets( input, ... ) == null ) break;      // handle input here } 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -