C Language Directory Management System curriculum design
- 2020-06-03 07:37:13
- OfStack
This paper shares the curriculum design of C language address book management system for your reference. The specific content is as follows
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
struct Sign{
char name[8];
char sex[4];
char birthday[12];
char phone[11];
char postcode[7];
char addr[30];
struct Sign *next;
}pe;
char PhoneCop[4] ;
// The structure of the body
struct Sign *p1,*p2,*head;
FILE *fp;
void ShowMenu(){
system("color 1F");
printf("################# Address book management system v1.0 ###################\n");
printf("#####################################################################\n");
printf("# #\n");
printf("# 1----------------- Information input ------------------- #\n");
printf("# #\n");
printf("# 2----------------- Information query ------------------- #\n");
printf("# #\n");
printf("# 3----------------- Check the information ------------------- #\n");
printf("# #\n");
printf("# 4----------------- Modify the information ------------------- #\n");
printf("# #\n");
printf("# 5----------------- Statistical information ------------------- #\n");
printf("# #\n");
printf("# 6----------------- Log out ------------------- #\n");
printf("# #\n");
printf("#####################################################################\n");
printf("# POWER BY ************* Lanzhou university of technology 201407 #\n");
printf("#####################################################################\n");
};
void HeadShow()
{
printf("################# Address book management system v1.0 ###################\n");
printf("---------------------------------------------------------------------\n");
}
void FileLoading()
{
if((fp=fopen("txl.dat","rb"))==NULL)
{
printf(" File operation error, please check whether there is permission to operate the file! ");
Sleep(3000);
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);
}
void add()
{
char ch;
if((fp==fopen("txl.dat","ab+"))!=1)
{
printf(" File opening failed ");
exit(1);
}
while(1)
{ system("cls");
printf(" Please enter the __\n");
p2=(struct Sign*)malloc(sizeof(struct Sign));
p2->next=NULL;
printf(" Name: ");scanf("%s",pe.name);
printf(" Gender: ");scanf("%s",pe.sex);
printf(" Birthday: ");scanf("%s",pe.birthday);
printf(" Telephone No. : ");scanf("%s",pe.phone);
printf(" Zip code: ");scanf("%s",pe.postcode);
printf(" Address: ");scanf("%s",pe.addr);
strcpy(p1->name,pe.name);
strcpy(p1->sex,pe.sex);
strcpy(p1->birthday,pe.birthday);
strcpy(p1->phone,pe.phone);
strcpy(p1->postcode,pe.postcode);
strcpy(p1->addr,pe.addr);
p1->next=p2;
p1=p2;
if(fwrite(&pe,sizeof(struct Sign),1,fp)!=1)
printf(" Write error ");
printf(" The input E or e To close the input? ");
getchar();
ch=getchar();
if(ch=='e'||ch=='E')
break;
}
fclose(fp);
}
void SaveChange()
{
if((fp==fopen("txl.dat","w"))!=1)
{
printf(" File opening 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);
}
void AllShow()
{
HeadShow();
printf("%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n"," The name "," gender "," birthday "," The phone "," Zip code "," address ");
printf("---------------------------------------------------------------------\n");
p1=head;
while(p1->next!=NULL)
{
printf("%10.8s %6.6s %10.12s %11.11s %9.7s %16.16s \n",p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr);
p1=p1->next;
}
}
void AllNum()
{ int i=0;
HeadShow();
printf(" The total number of records is: \n");
printf("---------------------------------------------------------------------\n");
p1=head;
while(p1->next!=NULL)
{
i++;
p1=p1->next;
}
printf(" %d \n",i);
printf("---------------------------------------------------------------------\n");
printf(" The total unicom users are: \n");
printf("---------------------------------------------------------------------\n");
p1=head;
i=0;
while(p1->next!=NULL)
{
strncpy(PhoneCop,p1->phone,3);
if(strcmp(PhoneCop,"130")==0||strcmp(PhoneCop,"131")==0||strcmp(PhoneCop,"132")==0||strcmp(PhoneCop,"155")==0||strcmp(PhoneCop,"156")==0||strcmp(PhoneCop,"185")==0||strcmp(PhoneCop,"186")==0)
i++;
p1=p1->next;
}
printf(" %d \n",i);
printf("---------------------------------------------------------------------\n");
printf(" The total mobile users are: \n");
printf("---------------------------------------------------------------------\n");
p1=head;
i=0;
while(p1->next!=NULL)
{
strncpy(PhoneCop,p1->phone,3);
if(strcmp(PhoneCop,"134")==0||strcmp(PhoneCop,"135")==0||strcmp(PhoneCop,"136")==0||strcmp(PhoneCop,"137")==0||strcmp(PhoneCop,"138")==0||strcmp(PhoneCop,"139")==0||strcmp(PhoneCop,"150")==0||strcmp(PhoneCop,"151")==0||strcmp(PhoneCop,"152")==0||strcmp(PhoneCop,"157")==0||strcmp(PhoneCop,"158")==0||strcmp(PhoneCop,"159")==0||strcmp(PhoneCop,"187")==0||strcmp(PhoneCop,"188")==0)
i++;
p1=p1->next;
}
printf(" %d \n",i);
printf("---------------------------------------------------------------------\n");
printf(" The total number of telecommunications users is: \n");
printf("---------------------------------------------------------------------\n");
p1=head;
i=0;
while(p1->next!=NULL)
{
strncpy(PhoneCop,p1->phone,3);
if(strcmp(PhoneCop,"180")==0||strcmp(PhoneCop,"189")==0||strcmp(PhoneCop,"133")==0||strcmp(PhoneCop,"153")==0)
i++;
p1=p1->next;
}
printf(" %d \n",i);
printf("---------------------------------------------------------------------\n");
}
void CheckFace()
{ int Check_key;
printf("########### Address book management system v1.0 ################\n");
printf("############################################################\n");
printf("# #\n");
printf("# 1------ Search by name #\n");
printf("# #\n");
printf("# 2------ Inquire by telephone number #\n");
printf("# #\n");
printf("# 3------ Integrated query #\n");
printf("# #\n");
printf("# 4------ Exit query module #\n");
printf("# #\n");
printf("# #\n");
printf("# #\n");
printf("############################################################\n");
printf("# POWER BY ************* Lanzhou university of technology 201407 #\n");
printf("############################################################\n");
}
void Selelctname()
{ system("cls");
HeadShow();
printf("%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n"," The name "," gender "," birthday "," The phone "," Zip code "," address ");
printf("---------------------------------------------------------------------\n");
p1=head;
char FindName[8];
int i=0;
printf(" Please enter the name of the query: ");
scanf("%s",&FindName);
while(p1->next!=NULL)
{
if(strcmp(p1->name,FindName)==0)
{printf("%10.8s %6.6s %10.10s %11.14s %9.7s %16.16s \n",p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr);
i++;
}
p1=p1->next;
}
printf(" A total of %d article \n",i);
system("pause");
}
void Selelctphone()
{ system("cls");
HeadShow();
printf("%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n"," The name "," gender "," birthday "," The phone "," Zip code "," address ");
printf("---------------------------------------------------------------------\n");
p1=head;
char phone[11];
int i=0;
printf(" Please enter the telephone number you want to check: ");
scanf("%s",&phone);
while(p1->next!=NULL)
{
if(strcmp(p1->phone,phone)==0)
{printf("%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n",p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr);
i++;
}
p1=p1->next;
}
printf(" A total of %d article \n",i);
system("pause");
}
void Selelctall()
{ system("cls");
HeadShow();
printf("%10.8s %6.6s %10.10s %11.4s %9.7s %16.6s \n"," The name "," gender "," birthday "," The phone "," Zip code "," address ");
printf("---------------------------------------------------------------------\n");
p1=head;
char all[30];
int i=0;
printf(" Please enter any 1 Item to query: ");
scanf("%s",&all);
while(p1->next!=NULL)
{
if(strcmp(p1->name,all)==0||strcmp(p1->sex,all)==0||strcmp(p1->birthday,all)==0||strcmp(p1->phone,all)==0||strcmp(p1->postcode,all)==0||strcmp(p1->addr,all)==0)
{printf("%10.8s %6.6s %10.10s %11.11s %9.7s %16.16s \n",p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr);
i++;
}
p1=p1->next;
}
printf(" A total of %d article \n",i);
system("pause");
}
void Change()
{ char ChangeName[8];
int changekey;
system("cls");
HeadShow();
int i,y=0;
p1=p2=head;
printf(" Please enter the name of the item you want to change: ");
scanf("%s",&ChangeName);
getchar();
while(p1!=NULL)
{
if(strcmp(p1->name,ChangeName)==0)
{ printf("%10.8s %6.6s %10.10s %11.11s %9.7s %16.16s \n",p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr);
printf(" Is this the record you want to modify? 1--- is |2--- no \n");
scanf("%d",&i);
if(i==1)
{ y=1;
printf(" The address book you want to change is :\n");
printf("%10.8s %6.6s %10.10s %11.11s %9.7s %16.16s \n",p1->name,p1->sex,p1->birthday,p1->phone,p1->postcode,p1->addr);
printf(" Please select your action 1--- delete |2--- Modify the \n");
scanf("%d",&changekey);
if(changekey==1)
{
if(p1==head)
{head=p1->next;
free(p1);
}
else
{
p2->next=p1->next;
free(p1);
SaveChange();
}
}
else if(changekey==2)
{
printf(" The name :");scanf("%s",p1->name);
printf(" gender :");scanf("%s",p1->sex);
printf(" birthday :");scanf("%s",p1->birthday);
printf(" The phone :");scanf("%s",p1->phone);
printf(" Zip code :");scanf("%s",p1->postcode);
printf(" address :");scanf("%s",p1->addr);
SaveChange();
printf("\n OK! \n");
}
}
}
else if(strcmp(p1->name,ChangeName)&&(p1->next)==NULL)
{
i=0;
}
p2=p1;
p1=p1->next;
}
if(y==0)
{
printf(" Sorry, there is no contact list to be changed. Please check if the name you want to change is correct \n");
}
system("pause");
}
void ExirShow()
{
system("color 0E");
printf("########### Address book management system v1.0 ################\n");
printf("############################################################\n");
printf("# #\n");
printf("# #\n");
printf("# #\n");
printf("# #\n");
printf("# #\n");
printf("# Thanks for using! #\n");
printf("# #\n");
printf("# #\n");
printf("# #\n");
printf("# #\n");
printf("# #\n");
printf("############################################################\n");
printf("# POWER BY ************* Lanzhou university of technology 201407 #\n");
printf("############################################################\n");
}
void ErrorShow()
{ int errortime=5;
system("color 0E");
for(errortime=5;errortime>0;errortime--)
{printf("\r Typo! Please check it carefully! Will be in %d Seconds after return ",errortime);
Sleep(1000);
}
}
int main()
{ int key;
int Ex_key;
int Check_key;
char a[10];
if((fp=fopen("txl.dat","ab"))==NULL)
{
printf(" File operation error, please check whether there is permission to operate the file! ");
Sleep(3000);
exit(1);
}
fclose(fp);
FileLoading();
while(1){
ShowMenu();
gets(a);
key=atoi(a);
if(key==1)
{system("cls");
add();
}
else if(key==2)
{ system("cls");
system("color 0E");
while(1)
{
system("color 0E");
CheckFace();
printf(" Please enter your choice :\n");
gets(a);
Check_key=atoi(a);
if(Check_key==1)
Selelctname()
;
else if(Check_key==2)
Selelctphone()
;
else if(Check_key==3)
Selelctall()
;
else if(Check_key==4)
break;
else
ErrorShow();
system("cls");
system("color 1F");
getchar();
}
}
else if(key==3) //2013 level Geng.
{ system("color 0E");
system("cls");
AllShow();
system("pause");
}
else if(key==4)
{
system("color 0A");
Change();
}
else if(key==5)
{
system("color 5F");
system("cls");
AllNum();
system("pause");
}
else if(key==6)
{
system("cls");
ExirShow();
Sleep(1000);
exit(0);
}
else
ErrorShow();
system("cls");
system("color 1F");
getchar();
}
}
It is relatively simple to use the linked list and file operation, where the statistics of the number of unicom and mobile there is actually only 1 loop can be used.