"C language" to implement a simple address book

Source: Internet
Author: User

<span style= "FONT-SIZE:18PX;" > #include <stdio.h> #include "contact.h" void Print_menu () {printf ("*******************************\n"); printf ("***1>add       2>del     ******\n");p rintf ("***3>search    4>modify  ******\n");p rintf (" 5>show      6>clear   ******\n ");p rintf (" *******************************\n ");} int main () {PCON pco;int input=1;pco.count=0;while (input) {print_menu ();p rintf ("Please select:"); scanf ("%d", &input); switch (input) {case 1:ADD_PEO (&PCO); Break;case 2:del_peo (&PCO); Break;case 3:search (&PCO); Break;case 4: Modify (&PCO); Break;case 5:show (&PCO); Break;case 6:clear (&PCO); break;default:break;}} return 0;} </span>
<span style= "FONT-SIZE:18PX;" > #ifndef __contact_h#define __contact_h_#define name_len 20#define sex_len 5#define tele_len 12#define ADDR_LEN 20# Define MAX_PEO 1000typedef struct Peo{char name[name_len];int age;char sex[sex_len];char Tele[tele_len];char addr[ADDR_ LEN];} peo,*ppeo;typedef struct CONTACT{PEO dhb[max_peo];//stores the information of the person int count;//record the number of valid persons}pcon,*pcon;void ADD_PEO (PCON PCON); void Del_peo (Pcon Pcon), void Search (Pcon Pcon), void Modify (Pcon Pcon), void Show (Pcon Pcon), void Clear (Pcon Pcon); #endif & Lt;/span>

<span style= "FONT-SIZE:18PX;" > #include <string.h> #include "contact.h" int find (Pcon Pcon) {int I=0;char Name[name_len];p rintf ("Please enter Name:"); scanf ("%s", name), for (i=0;i<=pcon->count;i++) {if (strcmp (name,pcon->dhb[i].name) ==0) return i;} return-1;} void Add_peo (Pcon Pcon) {if (PCON-&GT;COUNT&GT;MAX_PEO) printf ("Phone book is full"); else{printf ("Name:"); scanf ("%s", pcon->dhb[ Pcon->count].name);p rintf ("Age:"), scanf ("%d",& (pcon->dhb[pcon->count].age));p rintf ("Gender:"); scanf ("% S ", Pcon->dhb[pcon->count].sex);p rintf (" Phone: "), scanf ("%s ", Pcon->dhb[pcon->count].tele);p rintf (" Address: ") ; scanf ("%s", pcon->dhb[pcon->count].addr);} pcon->count++;p rintf ("added successfully! ")}void Del_peo (Pcon Pcon) {int i=0;int ret=find (Pcon), if (Ret!=-1) {for (i=ret;i<pcon->count-1;i++) {pcon-> DHB[I]=PCON-&GT;DHB[I+1];} pcon->count--;} elseprintf ("Person not found to delete");p rintf ("Delete succeeded! ");} void Search (Pcon Pcon) {int Ret=find (Pcon), if (ret!=-1) {printf ("%10s\t", Pcon->dhb[ret].name);p rintf ("%10d\t", Pcon->dhb[ret].age);p RinTF ("%10s\t", Pcon->dhb[ret].sex);p rintf ("%10s\t", Pcon->dhb[ret].tele);p rintf ("%10s\t", Pcon->dhb[ret]. addr);} elseprintf ("This person not Found");} void Modify (Pcon Pcon) {int Ret;ret=find (Pcon), if (ret!=-1) {printf ("Name:"), scanf ("%s", Pcon->dhb[ret].name);p rintf ("Age:"); scanf ("%d",& (pcon->dhb[ret].age));p rintf ("Gender:"); scanf ("%s", Pcon->dhb[ret].sex);p rintf ("Phone:") ; scanf ("%s", Pcon->dhb[ret].tele);p rintf ("Address:"); scanf ("%s", pcon->dhb[ret].addr);} elseprintf ("Person not found to be modified");} void Show (Pcon Pcon) {int i=0;for (i=0;i<pcon->count;i++) {printf ("%10s\t", Pcon->dhb[i].name);p rintf ("%10d\ T ", Pcon->dhb[i].age);p rintf ("%10s\t ", Pcon->dhb[i].sex);p rintf ("%10s\t ", Pcon->dhb[i].tele);p rintf ("% 10s\t ", pcon->dhb[i].addr);}} void Clear (Pcon Pcon) {pcon->count=0;} </span>


"C language" to implement a simple address book

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.