Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- // This source file needs to "know about" the structures you declared
- // in the header file before referring to those new types:
- // HINT: put the header file name in double quotes so the compiler knows
- // to look for it in the same directory/folder as this source file
- // #include your contacts header file on the next line:
- #include "contacts.h"
- int main(void) { //compiler looks for main function as a starting point. main returning 0 means everything is ok.
- // Declare variables here:
- // Create a variable of type Contact and call it something self-describing like "contact"
- // - HINT: Be sure to initialize the values to 0 and empty C strings
- // Declare variables here:
- Contacts contact = { {""}, {0,"",0,"",""},{""} };
- int key = 0; //declare flags
- // Display the title
- title();
- // Call the Contact function getName to store the values for the Name member
- getName(&contact.contactName, &promptYN);
- // Call the Contact function getAddress to store the values for the Address member
- getAddress(&contact.contactAddress, &promptYN, &key);
- if (key == 1) {
- return 0; //if user wants to exit program return
- }
- // Call the Contact function getNumbers to store the values for the Numbers member
- getPhone(&contact.contactNumbers, &promptYN);
- // Display Contact summary details
- displaySummary(contact);
- // Display Completion Message
- completion();
- return 0; //return 0 because function is type int.
- }
- void displaySummary(Contacts contact) { //takes 3 parameters with struct values
- //print title of summary
- printf("\nContact Details\n");
- printf("---------------\n");
- //print Name details
- printf("Name Details\n");
- printf("First name: %s\n", contact.contactName.firstName); //get value from firstName member
- printf("Middle initial(s): %s\n", contact.contactName.middleInitial); //get value from middleInitial member
- printf("Last name: %s\n\n", contact.contactName.lastName); //get value from lastName member
- //print address details
- printf("Address Details\n");
- printf("Street number: %d\n", contact.contactAddress.streetNumber); //get value from streetNumber member
- printf("Street name: %s\n", contact.contactAddress.street); //get value from street member
- printf("Apartment: %d\n", contact.contactAddress.apartmentNumber); //get value from apartmentNumber member
- printf("Postal code: %s\n", contact.contactAddress.postalCode); //get value from postalCode member
- printf("City: %s\n\n", contact.contactAddress.city); //get value from city member
- // print number details
- printf("Phone Numbers:\n");
- printf("Cell phone number: %s\n", contact.contactNumbers.cell);//get value from cell member
- printf("Home phone number: %s\n", contact.contactNumbers.home); //get value from home member
- printf("Business phone number: %s\n\n", contact.contactNumbers.business); //get value from business member
- }
- void title() { //function prints title of program
- printf("Contact Management System\n");
- printf("-------------------------\n");
- }
- void completion() { //function prints completion message
- printf("Structure test for Contact using functions done!\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement