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
2009-09-10 16:49:31
`enter` should be an int. Being a char there's no way to differentiate between EOF or a real character.
pmg
2009-09-10 19:17:23
What do you mean pmg?
bobobobo
2009-10-04 04:00:30
+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
2009-09-10 16:50:39