Press Enter to Continue in C
39,711
Solution 1
printf("Press enter to continue\n");
char enter = 0;
while (enter != '\r' && enter != '\n') { enter = getchar(); }
printf("Thank you for pressing enter\n");
Solution 2
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')
Related videos on Youtube
Author by
Smashery
Software Engineer. Coder for Trosnoth, a fun multiplayer game written in Python. #SOreadytohelp
Updated on September 11, 2020Comments
-
Smashery over 2 yearsHow can you do a "Press Enter to Continue" in C?
-
pmg over 13 yearsentershould be an int. Being a char there's no way to differentiate between EOF or a real character.