0

scanf asks for 2 values ​​for the first time enter image description here #define _CRT_SECURE_NO_WARNINGS Does not help I don't understand how to make scanf read only the first number please help solve the problem

void menu() {
    int n = 0;
    //setlocale(LC_ALL, "Rus");
    printf("1-input\n2-dobstr\n3-del\n4-check\n5-save\n6-upload\n7-vyvod\n8-sort\n9-exit\n");
    while (n != 9) {
        printf("what do you want to choose\n");
        scanf("%d\n", &n);
        switch (n != 9) {
        case 1:
            //vvod();
            break;
        case 2:
            //dobstr();
            break;
        case 3:
            //del();
            break;
        case 4:
            //check();
            break;
        case 5:
            //save();
            break;
        case 6:
            //upload();
            break;
        case 7:
            //vyvod();
            break;
        case 8:
            //sort();
            break;
        }
    }
}



int main(){
    menu();
}
disb4lance
  • 11
  • 1
  • 1
    Remove the newline from your format string. [What's the behavior of scanf when the format string ends with a newline?](https://stackoverflow.com/questions/10269208/whats-the-behavior-of-scanf-when-the-format-string-ends-with-a-newline) – Retired Ninja Apr 13 '23 at 21:16
  • Tip: Do not use `scanf();`. Use `fgets()` to read a line of user input into a string, then parse the string. – chux - Reinstate Monica Apr 13 '23 at 21:39

0 Answers0