Answered You can hire a professional tutor to get the answer.
When I run my code everything runs exactly as it should, but at the end of the program I receive an error messaging saying "Run-Time Check Failure #2...
When I run my code everything runs exactly as it should, but at the end of the program I receive an error messaging saying "Run-Time Check Failure #2 - Stack around the variable 'prompt' was corrupted". What is wrong inside my code for this error to be happening? My code is posted below.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include "contacts.h"
int main (void)
{
// Declare variables here:
struct Name name[] = { {''},{''},{''} };
struct Address address[] = { {0},{''},{0},{''},{''} };
struct Numbers phoneNum[] = { {''},{''},{''} };
char prompt = {''};
// Display the title
printf("Contact Management Systemn");
printf("-------------------------n");
// Contact Name Input:
printf("Please enter the contact's first name: ");
scanf(" %30[^n]", name->firstName);
do
{
printf("Do you want to enter a middle initial(s)? (y or n): ");
scanf("%s", &prompt);
} while ((prompt != 'Y') && (prompt != 'N') && (prompt != 'y') && (prompt != 'n'));
if (prompt == 'y' || prompt == 'Y')
{
printf("Please enter the contact's middle initial(s): ");
scanf(" %6[^n]", name->middleInitial);
}
printf("Please enter the contact's last name: ");
scanf(" %35[^n]", 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(" %40[^n]", address->street);
do
{
printf("Do you want to enter an apartment number? (y or n): ");
scanf("%s", &prompt);
} while ((prompt != 'Y') && (prompt != 'N') && (prompt != 'y') && (prompt != 'n'));
if (prompt == 'y' || prompt == 'Y')
{
printf("Please enter the contact's apartment number: ");
scanf("%d", &address->aptNumber);
}
printf("Please enter the contact's postal code: ");
scanf(" %7[^n]", address->postalCode);
printf("Please enter the contact's city: ");
scanf(" %40[^n]", address->city);
// Contact Numbers Input:
do
{
printf("Do you want to enter a cell phone number? (y or n): ");
scanf("%s", &prompt);
} while ((prompt != 'Y') && (prompt != 'N') && (prompt != 'y') && (prompt != 'n'));
if (prompt == 'y' || prompt == 'Y')
{
printf("Please enter the contact's cell phone number: ");
scanf("%10s", phoneNum->cell);
}
do
{
printf("Do you want to enter a home phone number? (y or n): ");
scanf("%s", &prompt);
} while ((prompt != 'Y') && (prompt != 'N') && (prompt != 'y') && (prompt != 'n'));
if (prompt == 'y' || prompt == 'Y')
{
printf("Please enter the contact's home phone number: ");
scanf("%10s", phoneNum->home);
}
do
{
printf("Do you want to enter a business phone number? (y or n): ");
scanf("%s", &prompt);
} while ((prompt != 'Y') && (prompt != 'N') && (prompt != 'y') && (prompt != 'n'));
if (prompt == 'y' || prompt == 'Y')
{
printf("Please enter the contact's business phone number: ");
scanf("%10s", phoneNum->business);
}
// Display Contact Summary Details
printf("nContact Detailsn");
printf("---------------n");
printf("Name Detailsn");
printf("First name: %sn", name->firstName);
if (strlen(name->middleInitial) != 0)
{
printf("Middle initial(s): %sn", name->middleInitial);
}
printf("Last name: %sn", name->lastName);
printf("nAddress Detailsn");
printf("Street number: %dn", address->streetNumber);
printf("Street name: %sn", address->street);
if (address->aptNumber != 0)
{
printf("Apartment: %dn", address->aptNumber);
}
printf("Postal code: %sn", address->postalCode);
printf("City: %sn", address->city);
printf("nPhone Numbers: n");
if (strlen(phoneNum->cell) != 0)
{
printf("Cell phone number: %sn", phoneNum->cell);
}
if (strlen(phoneNum->home) != 0)
{
printf("Home phone number: %sn", phoneNum->home);
}
if (strlen(phoneNum->business) != 0)
{
printf("Business phone number: %sn", phoneNum->business);
}
// Display Completion Message
printf("nStructure test for Name, Address, and Numbers Done!n");
return 0;
}