I'm having an issue with my code where the output will print statements earlier than I want it to and I was advised that it was due to input buffering and that adding a blank space before the "%" in my scanf would solve the problem but it is still a recurring issue.
printf("Please enter the contact's first name: "); scanf(" %31s", name.firstName);
printf("Do you want to enter a middle initial(s)? (y or n): ");
scanf(" %c", &option);
if (option == 'y' || option == 'Y')
{
printf("Please enter the contact's middle initial(s): ");
scanf(" %7s", name.middleInitial);
}
printf("Please enter the contact's last name: ");
scanf(" %36s", name.lastName);
// Contact Address Input:
printf("Please enter the contact's street number: ");
scanf(" %d", &address.streetNumber);
printf("Please enter the contact's street name: ");
scanf(" %41s", address.street);
printf("Do you want to enter an apartment number? (y or n): ");
scanf(" %c", &option);
if (option == 'y' || option == 'Y')
{
printf("Please enter the contact's apartment number: ");
scanf(" %d", &address.apartmentNumber);
}
printf("Please enter the contact's postal code: ");
scanf(" %8s", address.postalCode);
printf("Please enter the contact's city: ");
scanf(" %41s", address.city);
// Contact Numbers Input:
printf("Do you want to enter a cell phone number? (y or n): ");
scanf(" %c", &option);
if (option == 'y' || option == 'Y')
{
printf("Please enter the contact's cell phone number: ");
scanf(" %11s", numbers.cell);
}
printf("Do you want to enter a home phone number? (y or n): ");
scanf(" %c", &option);
if (option == 'y' || option == 'Y')
{
printf("Please enter the contact's home phone number: ");
scanf(" %11s", numbers.home);
}
printf("Do you want to enter a business phone number? (y or n): ");
scanf(" %c", &option);
if (option == 'y' || option == 'Y')
{
printf("Please enter the contact's business phone number: ");
scanf(" %11s", numbers.business);
}