int user_wishes_to_continue(void) { char c; do { printf("Do you wish to continue? (Y/N)"); scanf("%c", &c); clear_keyboard_buffer(); } while (c != 'y' && c != 'Y' && c != 'n' && c != 'N'); return (c == 'Y'); } void clear_keyboard_buffer(void) { char c = 'a'; while (c != '\n') { scanf_s("%c", &c); } return; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter