How can you do a "Press Enter to Continue" in C?
We should use "%[^\n]", which tells scanf() to take input string till user presses enter or return key. Scanf scans till user presses enter or till user presses return key.
In C programming, scanf() is one of the commonly used function to take input from the user. The scanf() function reads formatted input from the standard input such as keyboards.
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')
printf("Press enter to continue\n");
char enter = 0;
while (enter != '\r' && enter != '\n') { enter = getchar(); }
printf("Thank you for pressing enter\n");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With