-
Using EnterKey
I am creating a program that ask the user to input an integer value, if the user did not enter any value and click ENTER key, I want my program to read this as 1. Please help on how to implement this.
-
An enter key-press is equivalent to a newline character (\n). You can simply revise the received character from the user's input and check if it equals '\n'.
Note: If you are using a function such as gets() or anything similar, it wont return the new line character; rather, it will simply read nothing (since these functions read until a newline character is received).
You can make your own function which reads line per line using the getchar() function, as well.
Popular pages
Recent additions