Training in the first week of freshman year ,C Language programming , Choose one of the many titles I can write , Address book management system is a classic topic , In my heart and student status management system , Score statistical system . Share the code of address book management system today .

<> Small address book management system

Design a program to realize the management of address book , Able to add contacts , query , Delete and display functions , Store address book information in data file .
Specific requirements are as follows :
(1) Add function : According to the name of the contact entered , address , contact information ,QQ Number and other information , Add this contact to the address book ;
(2) Query function : According to the contact's name , Find information for this contact ;
(3) Delete function : By name , Delete the contact's information from the address book ;
(4) Display function : Output all address book information ;
(5) Design the system interface , The user enters from the keyboard 1 reach 4, The above can be realized respectively (1) reach (4) Function of .
#include<stdio.h> #include<stdlib.h> #include <windows.h> struct Sign { char
name[10]; char addr[20]; char tel[12]; char com[20]; struct Sign *next; }pe;
struct Sign *p1,*p2,*head; FILE *fp; void directory() /* Directory function */ { system("color
0D"); /*systemC Language function library stdlib.h A function in , color Change color ,0-9 Is the background color ,A-F Is the foreground color .*/ printf("\n\n"
); printf(" ----- Welcome to the address book management system ------\n"); printf("
*********************************\n"); printf(" * 1. Add a Contact *\n"); printf(" *
2. Query contact *\n"); printf(" * 3. Delete Contact *\n"); printf(" * 4. Show contacts *\n"); printf(" *
0. Exit address book service ; *\n"); printf(" *********************************\n"); printf("\n\n")
; } void add()/* Add a Contact */ { char ch; if((fp==fopen("txl.dat","a+"))!=1) { printf(
" File open failed "); exit(1); } while(1) { system("cls");/*cls function , Means to clear the screen */ printf(
" Please enter your personal information __\n"); p2=(struct Sign*)malloc(sizeof(struct Sign));/* Dynamic storage space */ p2->next
=NULL; printf(" full name :");scanf("%s",pe.name); printf(" address :");scanf("%s",pe.addr);
printf(" Telephone number :");scanf("%s",pe.tel); printf("QQ Signal or micro signal :");scanf("%s",pe.com);
strcpy(p1->name,pe.name); strcpy(p1->addr,pe.addr); strcpy(p1->tel,pe.tel );
strcpy(p1->com,pe.com); p1->next=p2; p1=p2; if(fwrite(&pe,sizeof(struct Sign),1,
fp)!=1) printf(" write error "); printf(" input E or e Return to home directory \n "); getchar(); ch=getchar(); if(
ch=='e'||ch=='E') break; } fclose(fp); } void Selelctname()/* Query information */ { system(
"cls"); p1=head; char FindName[8]; int i=0; printf("\n Please enter the name to query :"); scanf("%s",&
FindName); while(p1->next!=NULL) { if(strcmp(p1->name,FindName)==0) { printf(
"%10.8s %10.6s %12.10s %15.4s\n"," full name "," address "," Telephone number ","QQ No. or wechat "); printf("%10.8s
%10.6s %12.10s %15.14s\n",p1->name,p1->addr,p1->tel,p1->com); i++; } p1=p1->next
; } printf(" common %d strip \n",i); system("pause"); /*pause function , This means pausing the processing of batch files and displaying messages */ } void
Delete()/* Delete information */ { char DeleteName[8]; system("cls"); int i,y=0; p1=p2=head;
printf(" Please enter the name of the information you want to delete :"); scanf("%s",&DeleteName); getchar(); while(p1!=NULL) {
if(strcmp(p1->name,DeleteName)==0) { printf("\n%10.8s %10.6s %12.10s %15.4s\n",
" full name "," address "," Telephone number ","QQ No. or wechat "); printf("\n%10.8s %10.6s %12.10s %15.14s\n",p1->name,
p1->addr,p1->tel,p1->com); y=1; printf("\n Are you deleting this record ?1--- yes ;2--- no \n"); scanf(
"%d",&i); if(i==1) { if(p1==head) { head=p1->next; free(p1); } else { p2->next=
p1->next; free(p1); if((fp==fopen("txl.dat","w"))!=1) { printf(" File open failed "); exit(1
); } p1=head; while(p1->next!=NULL) { if(fwrite(p1,sizeof(struct Sign),1,fp)!=1)
printf(" write error "); p1=p1->next; } fclose(fp); } printf("\n OK! \n"); } else break;
} else if(strcmp(p1->name,DeleteName)&&(p1->next)==NULL) { i=0; } p2=p1; p1=p1->
next; } if(y==0) { printf(" I'm sorry , The address list to be deleted was not found , Please check whether the name you want to delete is correct \n"); } system("pause"
); } void Allshow()/* Show all contacts list */ { printf("\n%10.8s %10.6s %12.10s %15.4s\n",
" full name "," address "," Telephone number ","QQ No. or wechat "); p1=head; while(p1->next!=NULL) { printf("\n%10.8s
%10.6s %12.10s %15.14s\n",p1->name,p1->addr,p1->tel,p1->com); p1=p1->next; } }
void goodbye() { system("color 0E"); printf("\n\n"); printf("
----- Welcome to the address book management system ------\n"); printf(" *********************************\n");
printf(" * *\n"); printf(" * *\n"); printf(" * Thank you for using !bye bye *\n"); printf(" *
*\n"); printf(" * *\n"); printf(" *********************************\n"); printf(
"\n\n"); } void error() { system("color 0C"); system("cls"); printf("\n\n");
printf(" ----- Welcome to the address book management system ------\n"); printf("
*********************************\n"); printf(" * *\n"); printf(" * *\n");
printf(" * Input error ! Please check carefully ! *\n"); printf(" * *\n"); printf(" * *\n"); printf("
*********************************\n"); printf("\n\n"); system("pause"); } int
main() { int n; if((fp=fopen("txl.dat","a"))==NULL) { printf("File open
error!\n"); exit(1); } fclose(fp); if((fp=fopen("txl.dat","r"))==NULL) { printf(
"File open error!\n"); exit(1); } p1=(struct Sign*)malloc(sizeof(struct Sign));
p1->next=NULL; head=p1; while(!feof(fp)) { if(fread(p1,sizeof(struct Sign),1,fp)
!=1) break; p2=(struct Sign*)malloc(sizeof(struct Sign)); p2->next=NULL; p1->
next=p2; p1=p2; } fclose(fp); while(1) { directory(); printf(" Enter the function you want to apply (0-4):"
); printf(" "); scanf("%d",&n); if(n==0) { system("cls"); goodbye(); exit(0); }
else if(n==1) { system("color 0E"); system("cls"); add(); } else if(n==2) {
system("color 0C"); system("cls"); Selelctname(); } else if(n==3) { system(
"color 0A"); Delete(); } else if(n==4) { system("color 0B"); system("cls");
Allshow(); system("pause"); } else error(); system("cls"); getchar(); } }

Technology
Daily Recommendation