整理了一下文件,找到了去年做课程设计的报告,保存一下代码,有一个说法:过了6个月再去看自己写的代码,如果觉得写的不好,就说明有了一点进步;这样说明应该还是有那么一点点进步~
#include <stdio.h>#include <stdlib.h>#include <string.h>#include<conio.h>/*屏幕操作函数库*/#define header1 "|***********************通讯录***********************|\n"#define header2 "| 编号 | 姓名 | 电话号码|地址 |\n"#define header3 "|---------|-----------------|-------------------------|-----------------------|\n"#define end"|-----------------------------------结束-----------------------------------|\n"int input();int show();void dele();void save();int change();int cx();int find1();int find2();int find3();void quit();///结构体//struct telebook{int num;char name[20];char phonenum[20];char addr[30];};void printheader() /*格式化输出菜单头*/{printf(header1);printf(header2);printf(header3);}//////通讯信息录入///int input(struct telebook temp[]){char sign,x[20];int i=0;FILE *fp;/*定义文件指针*/system("cls");if((fp=fopen("telebook.txt","ab+"))==NULL)/* 若读写打开二进制文件telebook.txt失败,则显示出错信息 */{printf("打开文件有误!");exit(0);}while(sign!='n'&&sign!='N'){ printf("\t编号:");scanf("\t%d",&temp[i].num);printf("\t姓名:");scanf("\t%s",temp[i].name);printf("\t电话号码:");scanf("\t%s",temp[i].phonenum);printf("\t通讯住址:");scanf("\t%s",temp[i].addr);gets(x);printf("\n\t是否继续添加?(Y/N)");scanf("\t%c",&sign);i++;}fwrite(&temp[i],sizeof(struct telebook),1,fp);fclose(fp);system("cls");return 0;}///通讯信息显示//////int show(struct telebook temp[]){int i;printheader();for(i=0;i<100;i++){if(temp[i].num=='\0') break;printf("%-10d%-20s%-20s%-20s\n",temp[i].num,temp[i].name,temp[i].phonenum,temp[i].addr);}printf("-----------------------------------------------------\n");system("pause");system("cls");return 0;}/////通讯信息删除//void dele(struct telebook temp[]){char s[20];int i=0,j;show (temp);printf("\t请输入想删除记录中的名字:");scanf("%s",s);for(i=0;i<100;i++){if(strcmp(temp[i].name,s)==0){for(j=i;j<20;j++){temp[j]=temp[j+1];}printf("\t\t\t已经成功删除!\n");getch();system("cls");return ;}}printf("\t通讯录中没有此人!\n");getch();system("cls");}///通讯信息保存void save(struct telebook temp[]){int i;FILE*fp;if((fp=fopen("telebook.txt","w"))==NULL){printf("cannot open this file\n");exit(0);}for (i=0;strlen(temp[i].name)!=0;i++)fprintf(fp,"%d%s%s%s\n",temp[i].num,temp[i].name,temp[i].phonenum,temp[i].addr);fclose(fp);}///通讯信息修改////int change(struct telebook temp[]){char s[20];int i=0;show (temp);printf("\t请输入想修改的记录中的名字:");scanf("%s",s);for(i=0;i<100;i++){if(strcmp(temp[i].name,s)==0){printf("\t编号:");scanf("\t%d",&temp[i].num);printf("\t姓名:");scanf("\t%s",temp[i].name);printf("\t电话号码:");scanf("\t%s",temp[i].phonenum);printf("\t通讯住址:");scanf("\t%s",temp[i].addr);printf("\t修改成功!");getch();system("cls");return 0;}}{printf("\t通讯录中没有此人!\n");return;}getch();system("cls");}//////通讯信息查询////int cx(struct telebook temp[]){int n,flag=1;printf("你想通过什么方式查找?\n");printf("\t1.编号\t\t2.姓名\t\t3.电话号码\t4.返回\n");scanf("%d",&n);do{if(n==1) {find1(temp);return;}if(n==2) {find2(temp);return;}if(n==3) {find3(temp);return;}if(n==4) {system("cls");return ;}else{flag=0;printf("输入不正确,请重新输入:");scanf("%d",&n);}}while(flag==0);return 0;}////按编号查询int find1(struct telebook temp[]){int i=0,s=0;printf("\t请输入想查询的编号:");scanf("%d",&s);for(i=0;i<100;i++){if(temp[i].num=s){printheader();printf("%-10d%-20s%-20s%-20s\n",temp[i].num,temp[i].name,temp[i].phonenum,temp[i].addr);getch();system("cls");return 0;}}printf("\t通讯录中没有此人!\n");getch();system("cls");return 1 ;}/////按姓名查询///int find2(struct telebook temp[]){char s[20];int i=0;printf("\t请输入想查询的姓名:");scanf("%s",s);for (i=0;i<100;i++){if(strcmp(temp[i].name,s)==0){printheader();printf("%-10d%-20s%-20s%-20s\n",temp[i].num,temp[i].name,temp[i].phonenum,temp[i].addr);getch();system("cls");return 0;}}printf("\t通讯录中没有此人!\n");getch();system("cls");return 1;}//////按电话号码查询////int find3(struct telebook temp[]){char s[20];int i=0;printf("\t请输入想查询的电话:");scanf("%s",s);for (i=0;i<100;i++){if(strcmp(temp[i].phonenum,s)==0){printheader();printf("%-10d%-20s%-20s%-20s\n",temp[i].num,temp[i].name,temp[i].phonenum,temp[i].addr);getch();system("cls");return 0;}}printf("\t通讯录中没有此人!\n");getch();system("cls");return 1;}/退出/void quit(){ printf("\n");printf("\n");printf("\t\t★★★★★★★★★★★★★★★★★★★★★\n");printf("\t\t★★★★★★★感谢您的使用★★★★★★★★\n");printf("\t\t★★★★★★★欢迎再次使用★★★★★★★★\n");printf("\t\t★★★★★★★★★谢谢★★★★★★★★★★\n");exit(0);getch();system("cls");}//////主函数////int main(){struct telebook mess[100];char xx;system("color 2E");/*改变控制台颜色*/while(1){printf("\t★☆★☆★【欢迎进入通讯录管理系统】★☆★☆★\n");printf("\t\t******************menu********************\n");printf("\t\t┌───────────────────┐\n");printf("\t\t\t ●a、通讯信息录入\n");printf("\t\t\t ●b、通讯信息显示\n");printf("\t\t\t ●c、通讯信息保存\n");printf("\t\t\t ●d、通讯信息删除\n");printf("\t\t\t ●e、通讯信息修改\n");printf("\t\t\t ●f、通讯信息查询\n");printf("\t\t\t ◆Ⅰ、按编号查询\n");printf("\t\t\t ◆Ⅱ、按姓名查询\n");printf("\t\t\t ◆Ⅲ、按电话号码查询\n");printf("\t\t\t ●g、退出系统\n");printf("\t\t└───────────────────┘\n");printf("\t\t******************************************\n");printf("请输入您的选择\n");scanf("%c",&xx);getchar();system("cls");switch(xx){case 'a':input(mess);break;case 'b':show(mess);break;case 'c':save(mess);break;case 'd':dele(mess);break;case 'e':change(mess);break;case 'f':cx(mess);break;case 'g':quit();break;default:return 0;}getchar();}return 0;}
写的有点简陋,只是用来对照自己的学习状态,和以前进行比较,看现在有没有进步~ 以自己的过去为镜,时时激励自己!!!
如果觉得《课程设计——通讯录管理系统》对你有帮助,请点赞、收藏,并留下你的观点哦!