Recently reviewed the C language when I saw the internet has a C language Address Book Small project, so I looked at the next program to achieve the approximate function, and then I also followed a. The code is simple enough to be affixed to someone in need.
1 //2 //main.m3 //Adressbook4 //5 //Created by Bestkayle on 15/8/8.6 //Copyright (c) 2015 Bestkayle. All rights reserved.7 //8 9#import <Foundation/Foundation.h>Ten intAmount =1;//Contact Number One intNum//the input instruction A intXuhao;//Contact Number -typedefstructContact { - Charname[ -]; the intTelenumber; - }co; -Co person[ -] = { -{"Kayle",12345678}, + }; - voidaddcontracts () { + //for (int i = 0; i <; i + +) { A //For (int j = i; J < amount; J + +) { at //person[j+1] = person[j]; - // } - // } - } - voiddeletecontracts (Xuhao) { - for(inti = xuhao-1; I < amount; i++) { inPerson[i] = person[i+1]; - } to } + voidfixcontracts (Xuhao) { - the } * voidDisplayall () { $ for(inti =0; I < amount; i + +) {Panax Notoginsengprintf"%d.%s%d\n", i+1, person[i].name,person[i].telenumber); - } the } + voidSearchone (Xuhao) { Aprintf"%d.%s%d\n", xuhao,person[xuhao-1].name,person[xuhao-1].telenumber); the } + intMainintargcConst Char*argv[]) { -printf"**********************************\n"); $printf"****** Welcome to the address Book ************\n"); $printf"****** 1. Add a contact ************\n"); -printf"****** 2. Delete a contact ************\n"); -printf"****** 3. Modify the contact person ************\n"); theprintf"****** 4. View all contacts ************\n"); -printf"****** 5. Search Contact *************\n");Wuyiprintf"****** 6. Exit Address Book *************\n"); theprintf"***********************************\n"); -printf"Please follow the instructions: \ n"); Wu while(num! =6){ -scanf"%d",&num); About Switch(num) { $ Case 1: -Amount + +; - //addcontracts (); -printf"Please enter your name and phone number:"); A Charname[ -] = {0}; + intTelenumber; thescanf"%s%d",&*name,&telenumber); -strcpy (person[amount-1].name,name); $person[amount-1].telenumber =Telenumber; theprintf"has been deposited \ n"); the Break; the Case 2: theAmount--; -printf"Please enter the serial number:"); inscanf"%d",&Xuhao); the deletecontracts (Xuhao); the Break; About Case 3: theprintf"Please enter the serial number:"); thescanf"%d",&Xuhao); theprintf"to modify a contact Please enter 1, please enter the phone number 2:"); + intChoose; -scanf"%d",&choose); the if(Choose = =1) {Bayi Charname[ -] = {0}; theprintf"Please enter your name"); thescanf"%s", name); -strcpy (person[xuhao-1].name, name); - } the Else{ the intTelenumber; theprintf"Please enter your phone number"); thescanf"%d",&telenumber); -person[xuhao-1].telenumber =Telenumber; the } the Break; the Case 4:94 Displayall (); the Break; the Case 5: theprintf"Please enter the serial number:");98scanf"%d",&Xuhao); About Searchone (Xuhao); - default:101 Break;}102 if(num = =6) {103printf"exiting ... \ n");104Sleep1); theprintf"has exited!");106 }107 108 }109}
C language to do an address book program (run inside the console)