"C Language" address book production

Source: Internet
Author: User

This section is the header of the Address Book (HEAD.H)

This section is the most important part of the Address book, the function function (CONTACT.C)

#include "head.h" int find (PCon Pcon,char *name) {int i=0;for (i=0;i<pcon->count;i++) {if (strcmp (pcon-> Telbook[i]). Name,name) ==0) return i; return-1;} void Add_peo (PCon pCon) {if ((pcon->count) ==person_max) printf ("The Address Book is full, please delete and then Add.") \ n ");p rintf (" Name: "); scanf ("%s ", (Pcon->telbook[pcon->count]). Name);p rintf (" Gender: "); scanf ("%s ", pcon-> Telbook[pcon->count]). Sex);p rintf ("Age:"), scanf ("%d",& (Pcon->telbook[pcon->count]). Age);p rintf (" Tel: "); scanf ("%s ", (Pcon->telbook[pcon->count]). Tel);p rintf (" Home Address: "); scanf ("%s ", pcon->telbook[pcon- >count]). addr);p con->count++;} void Del_peo (PCon pCon) {int Ret=0;char Peoplename[name_max];p rintf ("Please enter the contact you want to delete:"); scanf ("%s", peoplename); ret=find (pcon,peoplename); if (ret==-1) {printf ("The contact does not exist. \ n ");} Else{int j;for (j=ret;j<pcon->count-1;j++) {pcon->telbook[j]=pcon->telbook[j+1];} printf ("Delete contact succeeded.") \ n ");} pcon->count--;} void Search_peo (PCon pCon) {int Ret=0;char Peoplename[name_max];p rintf ("Please enter the contact you are looking for:"); scanf ("%s", peoplename); ret=Find (Pcon,peoplename); if (ret==-1) {printf ("The contact does not exist. \ n ");} else{printf ("%s\t", (Pcon->telbook[ret]). Name);p rintf ("%s\t", (Pcon->telbook[ret]). Sex);p rintf ("%d\t", ( Pcon->telbook[ret]). Age);p rintf ("%s\t", (Pcon->telbook[ret]). Tel);p rintf ("%s\n", (Pcon->telbook[ret]). addr);}} void Modil_peo (PCon pCon) {int Ret=0;char Peoplename[name_max];p rintf ("Please enter the contact you want to modify:"); scanf ("%s", peoplename); ret= Find (Pcon,peoplename); if (ret==-1) {printf ("The contact does not exist. ");} else{printf ("Name:"); scanf ("%s", (Pcon->telbook[ret]). Name);p rintf ("Gender:"); scanf ("%s", (Pcon->telbook[ret]). Sex);p rintf ("Age:"); scanf ("%d",& (Pcon->telbook[ret]);p rintf ("Phone:"); scanf ("%s", Pcon->telbook[ret ]. Tel);p rintf ("Home Address:"); scanf ("%s", (Pcon->telbook[ret]). addr);}} void Show_peo (PCon pCon) {int i;for (i=0;i<pcon->count;i++) {printf ("%d.%s\t", I+1, (Pcon->telbook[i]). Name); printf ("%s\t", (Pcon->telbook[i]). Sex);p rintf ("%d\t", (Pcon->telbook[i]). Age);p rintf ("%s\t", pcon-> Telbook[i]). Tel);p rintf ("%s\n", pcon->Telbook[i]). addr);}} void Clear_peo (PCon pCon) {pcon->count=0;printf ("The contacts have been emptied. \ n ");}

This section is the Contacts Test section, which is the main function section (TEST.C)

 #include "head.h" void print () {printf ("********************************************* \ n ");p rintf (" | | | |        \ n ");p rintf (" | | 1. Add a contact 2. Delete a contact 3. Find a Contact | |        \ n ");p rintf (" | | 4. Modify the Contact 5. Show contacts 6. Clear Contacts | | \ n ");p rintf (" | | | | \ n ");p rintf (" ************************************************************************\n ");} int main () {struct contact my_contact;int input;my_contact.count=0;while (1) {print ();p rintf ("Select operation:"); scanf ("%d", &input); switch (input) {case 1:ADD_PEO (&my_contact); Break;case 2:del_peo (&my_contact); Break;case 3: Search_peo (&my_contact); Break;case 4:modil_peo (&my_contact); Break;case 5:show_peo (&my_contact); break ; case 6:clear_peo (&my_contact); break;default:printf ("Operation error \ n"); break;}} return 0;} 

Add a Contact


Delete a contact

Find a contact

Modify a contact

Show Contacts

Clear Contacts



"C Language" address book production

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.