Final answer:
To create a standalone C program that validates contact information, use loops to repeatedly prompt the user and validate each input using string functions in C. Display appropriate error messages if the data does not meet the validation rules. Once all data is entered and validated, display a success message.
Step-by-step explanation:
To create a standalone C program that validates the user's contact information, you can use the following steps:
- Declare variables to store the user's input for first name, last name, street, state abbreviation, zipcode, and phone number.
- Use loops to repeatedly prompt the user to enter their contact information until valid data is entered.
- For each input, use the appropriate string functions in C to check if the entered data meets the specified validation rules.
- If the data does not meet the validation rules, display an appropriate error message and ask the user to re-enter the data.
- Once all the data has been entered and validated, display a message confirming that the contact information has been successfully entered.
Here's an example of a C program that implements the above steps:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char firstName[100];
char lastName[100];
char street[100];
char state[3];
char zipcode[10];
char phone[15];
char city[100];
while (1) {
// Prompt and read first name
printf('Enter First Name: ');
fgets(firstName, sizeof(firstName), stdin);
firstName[strcspn(firstName, '
')] = 0; // Remove trailing newline
// Validate first name
int i;
for (i = 0; i < strlen(firstName); i++) {
if (!isalpha(firstName[i]) && firstName[i] != ' ') {
printf('Invalid First Name. Please enter only alphabetic characters and spaces.\\');
break;
}
}
if (i == strlen(firstName))
break;
}
// Repeat the code above for last name, street, state, zipcode, phone, and city
printf('Contact Information entered successfully!\\');
return 0;
}