当前位置:网站首页>Electronic address book management system based on C
Electronic address book management system based on C
2022-04-21 23:25:00 【Gentiana wild dust dream 520】
be based on C Electronic address book management system
The purpose and requirements of the experiment :
1. Further familiarity C The data type of the language 、 Operator 、 expression 、 Program control structure .
2. master C Language array and dynamic linked list skilled use .
3. master C The use of language pointers .4. master C The use of language structures .
5. master C Use of language file operation commands .
6. Through the comprehensive practice of the above knowledge, complete the coding of the electronic address book management system .
Program
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100struct record
{
// Keep your name
char name[20];
// Save email
char email[30];
// Keep your home address
char homeaddr[60];
// Save your phone number
char telephone[13];
}records[N]; // Array of structs
int i;
void Read_Data() /* Reading documents */
{
// explain fp Is a pointer , Used for pointing FILE Object of type
FILE*fp;
fp=fopen("D:\\yinzhihui.txt","a+");
/*fopen The function is to open a file , File pointer name =fopen( file name , Use file mode )*/ i=0;
while(!feof(fp))//feof: End of file , Return non 0 value , File not closed , return 0 value
{
fscanf(fp,"%s%s%s%s",records[i].name,records[i].email,records[i].homead dr,records[i].telephone);
i++;
}
fclose(fp);// If the stream closes successfully ,fclose return 0, Otherwise return to EOF(-1)
}
// Add a Contact
void Add_People(char name[20])
{
int j,n;
for(j=0;j<=i;j++) // Sort the added contacts by name
{
if(strcmp(records[j].name,name)>0)
break;//strcmp: Two strings are compared character by character from left to right ( Press ASCII value ), Until a different character appears or '\0' until
}
for(n=i;n>=j;n--) // Will be the first i The first message becomes the second i+1 individual
{
strcpy(records[n+1].name,records[n].name);/*trcpy Copy the last string to the previous array */
strcpy(records[n+1].email,records[n].email); strcpy(records[n+1].homeaddr,records[n].homeaddr); strcpy(records[n+1].telephone,records[n].telephone);
}
i++;
strcpy(records[j].name,name); // Save the contact name to the structure
printf("\n Please enter the email of the contact :");
scanf("%s",records[j].email);
printf("\n Please enter the contact's home address :");
scanf("%s",records[j].homeaddr);
printf("\n Please enter the contact's phone number :");
scanf("%s",records[j].telephone);
printf("\n Add success !\n");
}
int Search_Name(char namestr[20]) // Inquire about
{
int j;
for(j=0;j<=i;j++)
{
if(strcmp(namestr,records[j].name )==0)
break;
} // It's different , Same output
return j;
}
void DeletePeo() // Delete
{
char nametemp[20];
int tp,n;
if(i<1)
{
printf("\n No records deleted \n");
return;
}
printf(" Please enter the name of the contact you are looking for :");
scanf("%s",nametemp);
n=Search_Name(nametemp);
if(n>i)
{
printf(" To find the failure !\n");
return;
}
printf(" Are you sure you want to delete ? Confirm press 1, Otherwise, press any key to return to the previous menu !\n");
scanf("%d",&tp);
if(tp==1) // Confirm the input 1, Delete
{
int j;
for(j=n+1;j<=i;j++)
{
strcpy(records[j-1].name,records[j].name); strcpy(records[j-1].email,records[j].email); strcpy(records[j-1].homeaddr,records[j].homeaddr);
strcpy(records[j-1].telephone,records[j].telephone);
}
i--;
}
else return;
}
void Data_Show(int n) // Show
{
printf("%s %s %s %s\n",records[n].name,records[n].email,records[n].homeaddr,records[n].telephone);
}
void Change(char name[20]) // modify
{
int n,m;
char string[60];
n=Search_Name(name);// Judge whether the modified contact exists
if(n>i)
{
printf(" The contact you are looking for does not exist !\n");
return;
}
Data_Show(n); // Show contact information
printf(" Please select the data you want to modify :\n1 Modify contact name ;\n2 Modify contact email ;\n3 Modify contact address ;\n4 Modify contact phone number ;\n5 sign out !;\n\n");
scanf("%d",&m);
while(m!=5)
{
switch(m)
{
case 1:printf(" Please enter a new name :");
scanf("%s",string);
strcpy(records[n].name ,string);
break;
case 2:printf(" Please enter a new email :");
scanf("%s",string); strcpy(records[n].email ,string);
break;
case 3:printf(" Please enter a new address :");
scanf("%s",string);
strcpy(records[n].homeaddr ,string);
break;
case 4:printf(" Please enter a new phone number :");
scanf("%s",string);
strcpy(records[n].telephone ,string);
break;
case 5:return;
}
printf(" Please continue to select the data you want to modify :\n1 Modify contact name ;\n2 Modify contact email ;\n3 Modify contact address ;\n4 Modify contact phone number ;\n5 sign out !;\n\n");
scanf("%d",&m);
}
}
void Data_Save()// preservation
{
FILE*fp;int n;fp=fopen("D:\\yinzhihui.txt","w+"); // Save information to a file yinzhihui.txt in
for(n=0;n<=i;n++)
{
fprintf(fp,"%s %s %s %s",records[n].name,records[n].email,records[n].homeaddr,records[n].telephone);
fprintf(fp,"\n");
}
fclose(fp);
}
void main()
{
int ch,m,n;
char tp,nametemp[20];
Read_Data(); // Import the file data into the file yinzhihui.txt in
i--;
printf(" Electronic address book :\n");
printf(" Please select the operation you need :\n");
printf("1 modify ;\n2 View all contacts ;\n3 Delete Contact ;\n4 Query contact ;\n5 Add a Contact ;\n6 preservation ;\n7 sign out \n\n");
scanf("%d",&ch);
while(ch!=7)
{
switch(ch)
{
case 1:printf(" Please enter the contact name to modify :");
scanf("%s",nametemp);
Change(nametemp);
break;
case 2:for(m=0;m<=i;m++)Data_Show(m);
break;
case 3:DeletePeo();
break;
case 4:printf(" Please enter the name of the person you want to query :");
scanf("%s",nametemp);
n=Search_Name(nametemp);
if(n>i) printf(" There is no contact name you are looking for :");
else Data_Show(n);
break;
case 5:printf(" Please enter the name of the contact to be added :");
scanf("%s",nametemp);
Add_People(nametemp);break;
case 6:printf(" Save data ? OK press 8 key , Otherwise, press any key to select another operation !\n");
scanf("%d",&tp);
if(tp==8) Data_Save();
break;
case 7:return;
}
printf("\n1 modify ;\n 2 View all contacts ;\n 3 Delete Contact ;\n 4 Query contact ;\n 5 Add a Contact ;\n6 preservation ;\n 7 sign out \n\n");
scanf("%d",&ch);
}
}
result

版权声明
本文为[Gentiana wild dust dream 520]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212010297191.html
边栏推荐
- Red Star Macalline labor pains: "wield a knife" to reduce leverage and cut the net interest rate
- [openh264] timing of SPS_ info_ present_ flag
- selenium点击的元素被遮挡无法操作的解决办法
- The pattern should be large and the vision should be broad, and the humanitarian spirit should be upheld [continuous updating, do not delete]
- (7) Ruixin micro rk3568 builderoot adds compiled scripts and binary program files
- Sélection et évolution des microservices dans l'architecture native du cloud
- Selection and evolution of microservices under cloud native architecture
- VOS6. 0 installation and source code command
- Golang force buckle leetcode 2246 Longest path with different adjacent characters
- 【openh264】SPS的 timing_info_present_flag
猜你喜欢

2022 electrician (elementary) examination simulated 100 questions and simulated examination

Brush classic topics

【acwing】1125. Cattle travel * * * (Floyd)

Ijcai2022 employment results released! The acceptance rate is 15%. Did you win?

The three secret softwares of the leaders are practical and powerful, which are powerful tools for office efficiency and workplace promotion

prompt 你到底行不行?

340-Leetcode 有效的字母异位词

pytorch(五)——笔记

Ruixin microchip AI part development record section 1 "PC side environment construction 1"

Necessary skills for large factory interview, Android audio and video framework
随机推荐
【FFmpeg】命令行
"Inner universe" revolution link
Selection and evolution of microservices under cloud native architecture
2022/4/21
PP semantic retrieval system
golang力扣leetcode 388.文件的最长绝对路径
Custom login successfully processed
自定义模板问题求助,自动添加时间日期
云原生架构下的微服务选型和演进
Self made webserver from scratch (XVI) -- learn a new tool cmake to automatically write makefile and sort out source files by categories. Feel happy
痞子衡嵌入式:聊聊系统看门狗WDOG1在i.MXRT1xxx系统启动中的应用及影响
Sélection et évolution des microservices dans l'architecture native du cloud
Amazing, 4 high-quality software full of surprises, feel more comfortable to use
April 22, 2022 Daily: a new face attribute editing framework based on transformer
云原生架构下的微服务选型和演进
339 leetcode word rules
. 101 keyboard events
【ACM】46. Full Permutation (1. Here, the previous elements need to be used for permutation, so StartIndex is not used (only for combination and division); 2. Pay attention to whether the elements in t
Swoole high performance in memory database use and configuration tutorial
Ruixin microchip AI part development record section 1 "PC side environment construction 1"