tags:

views:

525

answers:

2

How can you do a "Press Enter to Continue" in C?

+16  A: 
printf("Press enter to continue\n");
char enter = 0;
while (enter != '\r' && enter != '\n') { enter = getchar(); }
printf("Thank you for pressing enter\n");
Dave DeLong
`enter` should be an int. Being a char there's no way to differentiate between EOF or a real character.
pmg
What do you mean pmg?
bobobobo
+13  A: 
printf("Press Enter to Continue");
while( getchar() != '\n' );

A check for '\r' is nice for ultimate portability, but really only matters if you are targeting Mac OS v9 or older (OS-X, Unix & Windows all use either '\n' or, for windows, '\r\n')

Eric Petroelje
+1 for succinctness
Dave DeLong