0

I have C code in VS which reads user input for different variables. The problem is that whichever of the variables is read first, it reads properly, but then does not continue with the next print statement, instead waiting again for user input. The second input is not stored in the variable, but is required to make the execution continue. Does anyone know how to fix this? The subsequent scanfs work fine, but the first one always errors. Here is the code causing the error:

    printf("Enter a first name: ");
    scanf("%s\n", &FName); //This will read a string, then after pressing enter create a newline
    printf("Enter a last name: "); //This is not executed until another character is entered
    scanf("%s\n", &LName);
    printf("Enter an ID: ");
    scanf("%s\n", &ID);
    printf("Enter an age: ");
    scanf("%d\n", &age);

Edit: Removing \n's from the scanfs solved the problem!

Blastfurnace
  • 18,411
  • 56
  • 55
  • 70
3mk05
  • 1
  • 1

0 Answers0