Explore BrainMass
Share

Using C Structure to store contact information

Write a C program that prompts the user to enter some information about up to ten individuals. It should store this information in a structure. The program should obtain the information from the structure, and output it as shown in attachment. Please see the attachment for complete information on the problem.

© BrainMass Inc. brainmass.com August 15, 2018, 10:23 am ad1c9bdddf

Attachments

Solution Preview

The attached program includes a structure with a tag name info.
It contains the following data as members:
a character array to store person's name, defined as: name[30]
a character array to store person's street address, defined as: address[30]
a character array to store person's city, defined as: city[20]
a character array to store person's state, defined as: state[3]
a long integer variable to store person's zip ...

Solution Summary

The attached program includes a structure with a tag name info.
It contains the following data as members:
a character array to store person's name, defined as: name[30]
a character array to store person's street address, defined as: address[30]
a character array to store person's city, defined as: city[20]
a character array to store person's state, defined as: state[3]
a long integer variable to store person's zip code, defined as: zip
an integer variable to store person's age, defined as: age
a character variable to store person's gender, defined as: gender

An array of type struct info has been declared called people[10].

An example dialog with the user is as follows:

Whatever Title you want Here
Enter name: Minnie Mouse
Enter street address: 100 Disney Drive
Enter city: Orlando
Enter state: FL
Enter zip code: 99990
Enter age: 25
Enter gender (M or F): F

Enter name: Big Bird
Enter street address: 10 Sesame Street
Enter city: Funtown
Enter state: MA
Enter zip code: 01222
Enter age: 20
Enter gender (M or F): M

The information you entered is:
Minnie Mouse
100 Disney Drive
Orlando, FL 99990
She is 25 years old.
Big Bird
10 Sesame Street
Funtown, MA 01222
He is 20 years old.

? Uses gets to read in more than one word at a time. (Needed for "name" , "address" and "city", in this program.)

? Uses fflush(stdin); This removes any extraneous characters (like carriage returns) from the input buffer.

? It tests for both uppercase, and lowercase values of M and F. For example, the user may enter "m" or "M" as the gender, in either case, the program interprets correctly that it is a male. (If neither M, m, F, or f is entered for gender, then the program does not display any age information.)

? Error checking is performed on the age input (allows between 1 and 120)

$2.19