To implement an address book:
Contacts can be used to store 1000 of people's information, and each person's information includes:
Name, gender, age, phone, address
Available methods:
1: Add contact information
2: Delete the specified contact information
3: Find specified contact information
4: Modify the specified contact information
5: Show All contact information
6: Clear All Contacts
#ifndef __contact_h_#define __contact_h_#define name_max 20#define sex_max 10#define tel_max 11#define ADDR_MAX 20# Define Peo_max 1000#include <stdio.h> #include <string.h> #include <stdlib.h>typedef struct people{ Char Name[name_max];char sex[sex_max];int Age;char Tel[tel_max];char Addr[addr_max];} *peo;typedef struct Contact{int count;struct people People[peo_max];} *pcon;void Add_peo (PCon pCon); void Del_peo (PCon pCon); void Find_peo (PCon pCon); void Modify_peo (PCon pCon); void Show_peo (PCon pCon); void Clear_peo (PCon pCon); #endif
#include "contact.h" int search (PCon Pcon,char *name) {int i = 0;for (; i < pcon->count; i++) {if (strcmp (name,pcon-> people[i].name) = = 0) return i;} return-1;} void Add_peo (PCon pCon)//Add contacts {if (Pcon->count = = Peo_max) {printf ("the contact has Fullen."); return;} printf ("Please input name:"); scanf ('%s ', (Pcon->people[pcon->count]). Name);p rintf ("Please input sex:"); scanf ( "%s", (Pcon->people[pcon->count]). Sex);p rintf ("Please input:"); scanf ("%d",& (pcon->people[pcon- >count]);p rintf ("Please input Tel:"); scanf ("%s", (Pcon->people[pcon->count]). Tel);p rintf ("please Input address: "); scanf ("%s ", (Pcon->people[pcon->count]). addr);p con->count++;} void Del_peo (PCon pCon)//delete contact {int I;char Name[name_max];p rintf ("Please input the people you want to delete:"); scanf ("%s" , name), I = Search (Pcon,name), if (i = =-1) printf ("The people doesn ' t exsit.\n"); else if (i = =) Pcon->count--;else{fo R (; i < pcon->count; i++) pcon->people[i] = pcon->PEOPLE[I+1];p con->count--;}} void Find_peo (PCon pCon)//Find contact {int I;char Name[name_max];p rintf ("Please input the people you want to find:"); scanf ("%s", name), I = Search (Pcon,name), if (i = =-1) printf ("The people doesn ' t exsit.\n"); elseprintf ("%s\t%s\t%d\t%s\t%s\n", pcon- >people[i].name,pcon->people[i].sex,pcon->people[i].age,pcon->people[i].tel,pcon->people[i]. addr);} void Modify_peo (PCon pCon)//modify Contact {int I;char Name[name_max];p rintf ("Please input the people you want to modify:"); scanf (" %s ", name), I = Search (Pcon,name), if (i = =-1) printf (" The people doesn ' t exsit.\n "); elseprintf (" Please input name: "); scanf ("%s", (Pcon->people[i]). Name);p rintf ("Please input Sex:"), scanf ('%s ', (Pcon->people[i]). Sex);p rintf ("please Input age: "); scanf ("%d ",& ((pcon->people[i)));p rintf (" Please input Tel: "); scanf ("%s ", pcon->people[ I]). Tel);p rintf ("Please input address:"); scanf ("%s", (Pcon->people[i]). addr); void Show_peo (PCon pCon)//display contact {int i = 0;for (; i < Pcon->count; i++) {printf ("%s\t%s\t%d\t%s\t%s\n", pcon->people[i].name,pcon->people[i].sex,pcon->people[i].age,pcon- >PEOPLE[I].TEL,PCON->PEOPLE[I].ADDR);}} void Clear_peo (PCon pCon)//empty contact {pcon->count = 0;}
#include "contact.h" void Show_menu ()//display Interface {printf ("************************\n");p rintf ("* 1:add 2:del *\n ");p rintf (" * 3:find 4:modify *\n ");p rintf (" * 5:show 6:clear *\n ");p rintf (" * * * * \ n ");} int main () {struct contact my_contact;//defines contacts human int input = 1;my_contact.count = 0;//number of contacts initialize while (input)//loop {Show_ Menu ();p rintf ("Please input:"); scanf ("%d", &input); switch (input) {case 1:ADD_PEO (&my_contact); Break;case 2: Del_peo (&my_contact); Break;case 3:find_peo (&my_contact); Break;case 4:modify_peo (&my_contact); break; Case 5:show_peo (&my_contact); Break;case 6:clear_peo (&my_contact); break;default:break;}} return 0;}
Write a 1000-person address Book in C-language multi-file