/* Filename: HW9.c*/ /* This program simulates an address book */ /****************************************************************** * Programmer: Matthew Glynn * * Date : 04/04/2007 * * Section Number: B36 * * Filename: HW9.c * * Description: This program simulates an address book * ******************************************************************/ /* libraries to be used */ #include #include #include #include #define MAX_count 3 //so that there will be a maximum of three entries struct name { char FirstName[21]; char LastName[21]; char title[6]; }; typedef struct name Name; // To avoid pointers struct address { char StreetNumber[21]; char StreetName[21]; char StreetAbbreviation[6]; char City[21]; char State[3]; int Zipcode; }; typedef struct address Address; // To avoid pointers struct entry { Name contact; Address home; int age; }; typedef struct entry Entry;// To avoid pointers int addEntry(Entry [], int); void printEntry(Entry [], int); int printmenu(void); phoneBook = 0; int main(void) { int selection, i; Entry book[MAX_count]; printf("\n This is an Address Book that holds three entries!\n"); do { selection = printmenu(); switch(selection) { case 1: phoneBook = addEntry(book, phoneBook); break; case 2: if(phoneBook == 0) printf("There are no entries in the Address Book\n"); else for(i=0; i \n"); fgets(entrystring, 500, stdin); sscanf(entrystring, "%s %s %s", field[0], field[1], field[2]); printf("\n Please the address in the following format: \n"); printf(" \n"); fgets(entrystring, 500, stdin); sscanf(entrystring, "%s %s %s %s %s %s", field[3], field[4], field[5], field[6], field[7], field[8]); printf("\n Please enter the contacts age in the following format: \n"); printf(" \n"); fgets(entrystring, 500, stdin); sscanf(entrystring, "%s", field[9]); printf("Name: %s %s %s\n", field[0], field[1], field[2]); printf("Address: %s %s %s\n", field[3], field[4], field[5]); printf(" %s %s %s\n", field[6], field[7], field[8]); printf("Age: %s\n", field[9]); } /*Copy the strings to the structures*/ strcpy (addr[count].contact.title, field[0]); strcpy (addr[count].contact.FirstName, field[1]); strcpy (addr[count].contact.LastName, field[2]); strcpy (addr[count].home.StreetNumber, field[3]); strcpy (addr[count].home.StreetName,field[4]); strcpy (addr[count].home.StreetAbbreviation, field[5]); strcpy (addr[count].home.City, field[6]); strcpy (addr[count].home.State, field[7]); addr[count].home.Zipcode = atoi(field[8]); addr[count].age = atoi(field[9]); //array to integer phoneBook = (phoneBook+1); /* Increment count for phoneBook */ } /****************************************************************** * * * Programmer: Matthew Glynn * * Name: printentry * * Function: This function prints the main menu of the program. * * Algorithm: uses printf to display messages and the * * quadraticcoefficient function * * Input: Entry addr[], int i * * * ******************************************************************/ void printEntry(Entry addr[], int i) { printf("\n Name: % 4s %s %s %s \n", "", addr[i].contact.title, addr[i].contact.FirstName, addr[i].contact.LastName); printf(" Address: %s %s %s %s \n", "", addr[i].home.StreetNumber, addr[i].home.StreetName, addr[i].home.StreetAbbreviation); printf("% 11s %s %s, %d \n", "", addr[i].home.City, addr[i].home.State, addr[i].home.Zipcode); printf(" Age: %10s%d\n \n", "", addr[i].age); return; }