I am stuck on a part of an assignment I am writing.
When I am typing in the postalCode (which is A8A 4J4
) it shows
It is supposed to be:
Postal code: A8A 4J4
City: Toronto
It is skipping the option to enter the City.
I've tried %[^\n]
and it still skips the option to enter the City.
My current code is:
if (option == 'y' || option == 'Y') {
printf("Please enter the contact's apartment number: ");
scanf("%u", &address.apartmentNumber);
printf("Please enter the contact's postal code: ");
scanf("%s", &address.postalCode);
}
if (option == 'n' || option == 'N') {
printf("Please enter the contact's postal code: ");
scanf("%s", &address.postalCode);
}
printf("Please enter the contact's city: ");
scanf("%40s", address.city);
printf("Postal code: %s\n", address.postalCode);
printf("City: %s\n", address.city);
I saw a post about this already but the answers there didn't help. I already tried the [^\n] in my scanf
.