c语言电话本编程课程设计完整版
计算机程序设计(c语言)
课程设计报告
题目:通讯录
学院:
专业:
班级:
姓名:
指导教师:
答辩日期: 年 月 日
一、 设计背景介绍 二、 任务概述部分三、 设计流程
四、 #include
struct person
{
char name[8];
char QQ[15];
char tel[15];
char addr[50];
};
char filename[20];
void creat();
void search();
void append();
void modify();
void delete();
FILE *fp;
main()
{
int m;
creat();
while(1)
{
printf("\n\append,please enter1");
printf("\nsearch, please enter,2");
printf("\nmodify, please enter3");
printf("\ndelete, please enter4");
printf("\nexit, please enter0\n");
scanf("%d",&m);
if(m>=0&&m<=4)
{
switch(m)
{
case 1:append();
break;
case 2:search();
break;
case 3:modify();
break;
case 4:delete();
break;
case 0:exit();
}
printf("\n\nend edited please select");
}
else
printf("\n\nerror please try again");
}
}
void creat()
{
struct person one;
printf("\nplease input a filename:");
scanf("%s",filename);
if((fp=fopen(filename,"w"))==NULL)
{
printf("\ncan not establish a filename");
exit();
}
fclose(fp);
}
void append()
{
struct person one;
if((fp=fopen(filename,"a"))==NULL)
{
printf("\ncan not open the file");
exit();
}
printf("\nplease input the name:\n");
scanf("%s",one.name);
printf("\nplease input the QQ:\n");
scanf("%s",one.QQ);
printf("please input the tel:\n");
scanf("%s",one.tel);
printf("\nplease input the address:\n");
scanf("%s",one.addr);
fprintf(fp, "%-10s\n",one.name);
fprintf(fp, "%-20s\n",one.QQ);
fprintf(fp, "%-20s\n",one.tel);
fprintf(fp, "%-50s\n",one.addr);
fclose(fp);
}
void search()
{
int k=0;
char namekey[8];
struct person one;
printf("\nplease input a name:");
scanf("%s",namekey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\ncan not open the file");
exit();
}
while(!feof(fp))
{
fscanf(fp,"%s\n",one.name);
fscanf(fp,"%s