1
if (choice=1){
    printf("Enter the name of the patient:\n");
    scanf("%d", name);
    printf("Enter the date of birth of the patient:\n");
    scanf("%s", birthmonth, birthday, birthyear);
    printf("Enter the gender of the patient:\n");
    scanf("%s", gender);
    printf("PRESS ANY KEY TO CONTINUE");
    getch();
            
}

Whenever I run this part of my code, it only allows me to enter the name of the patient. Does anyone know why this happens?

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • Are you trying to enter a full name, with a space between the first and the last name? Also, is this C++ or C code? – Nathan Pierson Apr 16 '21 at 05:23
  • https://stackoverflow.com/questions/9562218/c-multiple-scanfs-when-i-enter-in-a-value-for-one-scanf-it-skips-the-second-s – Jonathon Reinhart Apr 16 '21 at 05:25
  • Additionally to [this](https://stackoverflow.com/questions/5240789) you are telling scanf to read one number as patient name. So as long as you don't enter a number, it won't advance. I guess you wanted `%s` instead of `%d`. Plus, a long name could then crash your program, so you should limit the length to the size of your string, for example `%20s`. But then you'll have another issue with the birthdate, there you are reading one string but specifying three variables. If your variables are integers, you likely want something like `scanf("%d/%d/%d", &birthmonth, &birthday, &birthyear)` instead. – CherryDT Apr 16 '21 at 05:41

1 Answers1

2

You're using an integer placeholder (%d) instead of (%s) for a string in the first scanf statement.

And in the second scanf statement, you should be using 3x %s, to get input to the three variables.

CherryDT
  • 25,571
  • 5
  • 49
  • 74