C语言程序设计—通讯录管理系统

2024-11-23 09:05:48
推荐回答(3个)
回答1:

这个东西可以运行但是写的不怎么样,你自己改哈就对了,我没有时间我就不给你改了,希望对你有帮助!

#include
#include
//person结构定义
struct person
{
char name[8];
char tel[15];
char addr[50];
};//结束定义
char filename[20];
FILE *fp;
void creat();
void ndelete();
void output();
void search();
void search1();
void search2();
void append();

main( )

{
int m;
creat();
while(1)
{
printf("\n\t\t***********欢迎使用电话查询系统**********\n\n");
printf("\n\t\t添加, 请按1");
printf("\n\t\t按姓名查找,请按2");
printf("\n\t\t按号码查找, 请按3");
printf("\n\t\t输出, 请按4");
printf("\n\t\t退出, 请按0\n");
printf("\n\t\t********************************************\n\n");
printf("Please select(0--4):");
scanf("%d",&m);
if(m>=0&&m<=4)
{
switch(m)
{
case 1: append();
break;
case 2: search();
break;
case 3: search1();
break;
case 4: output();
break;
case 0: exit();
}
printf("\n\n操作完毕,请再次选择!");
}
else
printf("\n\n选择错误,请再次选择!");
}
}

/*输入模块creat( ): 电话薄的子函数。*/
void creat()
{
printf("\n请确定电话薄文件名:");
scanf("%s",filename);

if((fp=fopen(filename,"at+"))==NULL)
{
printf("\n不能建电话薄录!");
exit();
}
fprintf(fp,"%-10s%-20s%-50s\n","姓名","电话号码","住址");

fclose(fp);
}

/*输出模块output( ):输出电话薄中联系人的个人信息的子函数*/
void output()
{
struct person one;
if((fp=fopen(filename,"r"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
printf("\n\n%20s\n","通 讯 录");
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
printf("%-10s%-20s%-50s",one.name,one.tel,one.addr);
}
fclose(fp);
}

/*添加模块append( ):向电话薄中添加某人的个人信息的子函数*/
void append()
{
struct person one;
search2();
if((fp=fopen(filename,"a"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
printf("\n请输入添加的姓名、电话号码及住址\n");
scanf("%s%s%s",one.name,one.tel,one.addr);
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
fclose(fp);
}
/*查找模块search( ):在电话薄中按姓名查找某人的个人信息的子函数*/
void search()
{
int k=0;
char namekey[8];
struct person one;
printf("\n请输入姓名:");
scanf("%s",namekey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\n不能打开电话薄!");
exit();
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
printf("\n\n已查到,记录为:");
printf("\n%-10s%-20s%-50s",one.name,one.tel,one.addr);
k=1;
}
}
if(!k)
printf("\n\n对不起,电话薄中没有此人的记录。");
fclose(fp);
}

/*查找模块search1( ):在电话薄中按电话号码查找某人的个人信息的子函数*/
void search1()
{
int k=0;
char telkey[15];
struct person one;
printf("\n请输入电话号码:");
scanf("%s",telkey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\n不能打开电话薄!");
exit();
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(telkey,one.tel))
{
printf("\n\n已查到,记录为:");
printf("\n%-10s%-2s%-50s",one.name,one.tel,one.addr);
k=1;
}
}
if(!k)
printf("\n\n对不起,电话薄中没有此人的记录。");
fclose(fp);
}

/*查找模块search( ):在电话薄中按姓名查找某人的个人信息的子函数*/
void search2()
{
int k=0;
char namekey[8];
struct person one;
printf("\n请输入添加的姓名:\n");

scanf("%s",namekey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\n不能打开电话薄!");
exit();
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);

if(!strcmp(namekey,one.name))
{
printf("\n\n查到有同名记录为:");
printf("\n%-10s",one.name);
k=1;
printf("\n\n请改名字后继续完成添加\n");
}

}

fclose(fp);
}

回答2:

这个东西可以运行但是写的不怎么样,你自己改哈就对了,我没有时间我就不给你改了,希望对你有帮助!
#include
#include
//person结构定义
struct
person
{
char
name[8];
char
tel[15];
char
addr[50];
};//结束定义
char
filename[20];
FILE
*fp;
void
creat();
void
ndelete();
void
output();
void
search();
void
search1();
void
search2();
void
append();
main(
)
{
int
m;
creat();
while(1)
{
printf("\n\t\t***********欢迎使用电话查询系统**********\n\n");
printf("\n\t\t添加,
请按1");
printf("\n\t\t按姓名查找,请按2");
printf("\n\t\t按号码查找,
请按3");
printf("\n\t\t输出,
请按4");
printf("\n\t\t退出,
请按0\n");
printf("\n\t\t********************************************\n\n");
printf("Please
select(0--4):");
scanf("%d",&m);
if(m>=0&&m<=4)
{
switch(m)
{
case
1:
append();
break;
case
2:
search();
break;
case
3:
search1();
break;
case
4:
output();
break;
case
0:
exit();
}
printf("\n\n操作完毕,请再次选择!");
}
else
printf("\n\n选择错误,请再次选择!");
}
}
/*输入模块creat(
):
电话薄的子函数。*/
void
creat()
{
printf("\n请确定电话薄文件名:");
scanf("%s",filename);
if((fp=fopen(filename,"at+"))==NULL)
{
printf("\n不能建电话薄录!");
exit();
}
fprintf(fp,"%-10s%-20s%-50s\n","姓名","电话号码","住址");
fclose(fp);
}
/*输出模块output(
):输出电话薄中联系人的个人信息的子函数*/
void
output()
{
struct
person
one;
if((fp=fopen(filename,"r"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
printf("\n\n%20s\n","通

录");
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
printf("%-10s%-20s%-50s",one.name,one.tel,one.addr);
}
fclose(fp);
}
/*添加模块append(
):向电话薄中添加某人的个人信息的子函数*/
void
append()
{
struct
person
one;
search2();
if((fp=fopen(filename,"a"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
printf("\n请输入添加的姓名、电话号码及住址\n");
scanf("%s%s%s",one.name,one.tel,one.addr);
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
fclose(fp);
}
/*查找模块search(
):在电话薄中按姓名查找某人的个人信息的子函数*/
void
search()
{
int
k=0;
char
namekey[8];
struct
person
one;
printf("\n请输入姓名:");
scanf("%s",namekey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\n不能打开电话薄!");
exit();
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
printf("\n\n已查到,记录为:");
printf("\n%-10s%-20s%-50s",one.name,one.tel,one.addr);
k=1;
}
}
if(!k)
printf("\n\n对不起,电话薄中没有此人的记录。");
fclose(fp);
}
/*查找模块search1(
):在电话薄中按电话号码查找某人的个人信息的子函数*/
void
search1()
{
int
k=0;
char
telkey[15];
struct
person
one;
printf("\n请输入电话号码:");
scanf("%s",telkey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\n不能打开电话薄!");
exit();
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(telkey,one.tel))
{
printf("\n\n已查到,记录为:");
printf("\n%-10s%-2s%-50s",one.name,one.tel,one.addr);
k=1;
}
}
if(!k)
printf("\n\n对不起,电话薄中没有此人的记录。");
fclose(fp);
}
/*查找模块search(
):在电话薄中按姓名查找某人的个人信息的子函数*/
void
search2()
{
int
k=0;
char
namekey[8];
struct
person
one;
printf("\n请输入添加的姓名:\n");
scanf("%s",namekey);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("\n不能打开电话薄!");
exit();
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
printf("\n\n查到有同名记录为:");
printf("\n%-10s",one.name);
k=1;
printf("\n\n请改名字后继续完成添加\n");
}
}
fclose(fp);
}

回答3:

我也正在学