• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Accept default value at user input


New Coder
Hello again
Trying to find a method that when prompted to enter a value, the user presses the 'Enter' key for the program to accept a default value. Apparently there is not a consistent ascii code of 'Enter' that I can use to compare, if I understand it correctly. Here is a snippet of my example. I used the highlight option this time- not sure if correctly.

btw, the code, in entirety, works. Thanks.

Edit- I don't see anything highlighted :confused:

int h, temp, response = 0;
int local_press = 760;

printf("\n1\tAtmospheric pressure known (mmHg) <760>\n");
printf("2\tAltitude and air temperature known\n");
printf("\nPlease enter a choice (1 or 2): ");
response = get_user_input();

   if (response == 1 )
   printf("\n Enter Atmospheric Pressure [mmHg] <760>");
   local_press = get_user_input();
   printf("\n Enter Altitude [Meters]:");
   h = get_user_input();
   printf("\n Enter Air Temperature [Celcius]: ");
   temp = get_user_input();
   local_press = calc_atm_press(h, temp);


Active Coder
Staff Team
I used the highlight option this time- not sure if correctly.
What I meant was selecting 'C' in the language when you include code ;).
Here an example:
#include <stdio.h>

int main()
    char c = getchar();

    if(c == '\n')
        printf("Key: %c.\n", c);

    return 0;
The character '\n' equals 'enter'.
If the value of the character is 'enter', you use the default value. Otherwise, you read the rest of the string (With scanf or something).
Last edited: