The "C Language" address book is implemented.

Source: Internet
Author: User

Implement an Address Book: Contacts are used to hold 1000 people's information, each person's information includes: name, gender, age, telephone, Address Provision Method: (1) Add contact information (2) Delete the specified contact information (3) Find information for the specified contacts (4) Modify the specified contact information (5) Show all contact information (6) Clear all Contacts implementation method:

#include <stdio.h>#include <string.h>#define MAX#define Name_len#define Sex_len 5#define Phone_len#define Address_lenstructdhb{CharName[name_len];CharSex[sex_len];intAgeCharPhone[phone_len];CharAddress[address_len];};typedef structpeo{structDHB Dhb[max];intCount;} Peo,*pcon;voidPrintvoid){printf("***********\n");printf("1-> Add contact \n2-> Delete the specified contact \n3-> find the specified contact \ n");printf("4-> Modify the specified contact \n5-> Show all contacts \n6-> clear all contacts \ n");printf("***********\n");printf("\ n Please select the serial number:");}intFindChar*p,pcon Pcon) {inti =0; for(i =0; I < pcon->count; i++) {if(strcmp(p, pcon->dhb[i].name) = =0)        {returnI }    }return-1;}voidAdd (Pcon Pcon) {printf("Please enter your name, gender, age, phone number, address: \ n");scanf('%s%s%d%s%s ', Pcon->dhb[pcon->count].name, Pcon->dhb[pcon->count].sex, &pcon->dhb[pcon->co Unt].age, Pcon->dhb[pcon->count].phone, pcon->dhb[pcon->count].address);printf("\ n"); pcon->count++;}voidDele (Pcon Pcon) {inti =0, TMP =0;CharName[name_len];printf("Enter the name of the contact you want to delete:");scanf('%s ', name); TMP = FIND (Name,pcon);if(TMP = =-1)    {printf("no contact!\n"); }Else{ for(i=tmp; i < pcon->count-1; i++) {Pcon->dhb[i] = pcon->dhb[i +1]; } pcon->count--;printf("\ nthe deletion of the specified contact succeeded!\n"); }}voidSearch (Pcon Pcon) {intTMP =0;CharName[name_len];printf("Please enter the name of the contact you want to find:");scanf('%s ', name); TMP = FIND (name, Pcon);if(TMP = =-1)    {printf("no contact!\n"); }Else{printf("%s%s%d%s%s\n", Pcon->dhb[tmp].name, Pcon->dhb[tmp].sex, Pcon->dhb[tmp].age, pcon-& Gt;dhb[tmp].phone, pcon->dhb[tmp].address);printf("\ n Find success!\n"); }}voidModify (Pcon Pcon) {intTMP =0;CharName[name_len];printf("Please enter the name of the contact you want to modify:");scanf('%s ', name); TMP = FIND (Name,pcon);if(TMP = =-1)    {printf("no contact!\n"); }Else{printf("Please enter all information for the modified contact: \ n");scanf('%s%s%d%s%s ', Pcon->dhb[tmp].name, Pcon->dhb[tmp].sex, &pcon->dhb[tmp].age, Pcon->dhb[tmp].phone, pcon->dhb[tmp].address);printf("\ n Modify success!\n"); }}voidShow (Pcon Pcon) {inti =0;printf("name sex age phone address \ n");printf("----------------------------------------------------"); for(i =0; I < pcon->count; i++) {printf("\n%-8s%-7s%-7d%-9s%-11s\n", Pcon->dhb[i].name, Pcon->dhb[i].sex, Pcon->dhb[i].age, PCON-&GT;DHB    [I].phone, pcon->dhb[i].address]; }}voidClear (Pcon Pcon) {Pcon->count =0;}intMain () {Peo stu;intinput =1; Stu.count =0; while(input) {print ();scanf("%d", &input);Switch(input) { Case 1: Add (&stu); Break; Case 2: Dele (&stu); Break; Case 3: Search (&stu); Break; Case 4: Modify (&stu); Break; Case 5: Show (&stu); Break; Case 6: Clear (&stu); Break;default:printf("Invalid option \ n"); Break; }    }return 0;}
To add a contact:

Find a specific contact:

The "C Language" address book is implemented.

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.