求用C语言编写一个 通讯录管理系统 。设计要求如下
设计和实现一个“通信录管理系统”,实现对个人通信录进行管理,并满足以下要求:1.系统以菜单方式工作;2.使用链表对通信录信息进行管理和维护;3.使用二进制文件在磁盘上保存...
设计和实现一个“通信录管理系统”,实现对个人通信录进行管理,并满足以下要求:
1.系统以菜单方式工作;
2.使用链表对通信录信息进行管理和维护;
3.使用二进制文件在磁盘上保存通信录信息;
4.链表中每个结点包括“姓名、手机、电子邮箱、类别(假设类别共分为A、 办公类, B、个人类, C、 商务类三种类别)”基本字段;
5.实现如下基本功能:
(1)新增通信录 (假设姓名不重复,若录入了重复的姓名时,系统能提出错误提示)
(2)通信录浏览功能(输出所有的个人通信录信息)
(3)通信录查询 (按姓名查询通信录)
(4)通信录统计 (提供按类别显示通信录的功能)
(5)通信录删除 (从链表中删除指定姓名的通信录)
(6)通信录修改 (修改指定姓名的通信信息)
(7)将通信录保存到文件存盘 (将建立起来的链表以文件的形式存盘)
(8)从文件中读入通信录 (将原来已经存盘的文件读入内存,进行管理) 展开
1.系统以菜单方式工作;
2.使用链表对通信录信息进行管理和维护;
3.使用二进制文件在磁盘上保存通信录信息;
4.链表中每个结点包括“姓名、手机、电子邮箱、类别(假设类别共分为A、 办公类, B、个人类, C、 商务类三种类别)”基本字段;
5.实现如下基本功能:
(1)新增通信录 (假设姓名不重复,若录入了重复的姓名时,系统能提出错误提示)
(2)通信录浏览功能(输出所有的个人通信录信息)
(3)通信录查询 (按姓名查询通信录)
(4)通信录统计 (提供按类别显示通信录的功能)
(5)通信录删除 (从链表中删除指定姓名的通信录)
(6)通信录修改 (修改指定姓名的通信信息)
(7)将通信录保存到文件存盘 (将建立起来的链表以文件的形式存盘)
(8)从文件中读入通信录 (将原来已经存盘的文件读入内存,进行管理) 展开
3个回答
展开全部
这个主要用到链表来做就可以的啦,链表的基本操作(创建、插入、删除等)要掌握好。之前我自己写有一个,和你的功能差不多,但是变量有所不同,给你参考参考吧,可以仿照。不懂的再问吧。代码如下:
#include"stdafx.h"
using namespace std;
//结构体
struct contaxt
{
char name[10];
char sex[5];
char Adrre[50];
char Class[20];
char Mobi[20];
char qq[10];
struct contaxt *next;
};
//函数声明
typedef struct contaxt CONT;
CONT *InsertCon(CONT *head);
CONT *AddContaxt(int n);
CONT *FindCon(CONT *head);
CONT *AmendMessage(CONT *head);
CONT *DeleteMessage(CONT *head);
void showmessage(CONT *head);
int menu(CONT *head);
CONT *saveFileCONT(CONT *head );
CONT *readFileCONT(CONT *head);
int choose;
//入口
void main()
{
//system("color F4");
CONT *head;
head = NULL;
menu(head);
}
//系统主菜单
int menu(CONT *head)
{
cout << "请选择操作菜单!!!" << endl ;
do
{
cout << "---------------------------欢迎进入通讯录管理系统-------------------------------"
<< "---------------------------------操作菜单---------------------------------------";
cout << "--------------------------------------------------------------------------------"
<< " 1 添加联系人信息 "
<< " 2 插入联系人信息 " << endl
<< " 3 查找联系人信息 "
<< " 4 修改联系人信息 " << endl
<< " 5 删除联系人信息 "
<< " 6 显示联系人信息 " << endl
<< " 7 退出本系统 " << endl
<< " 8 保存文件 " << endl
<< " 9 读取文件 " << endl
<< "--------------------------------------------------------------------------------" << endl;
cout << "请选择操作菜单!!!" << endl ;
int choose;
//choose = getchar();
fflush(stdin);
//return choose;
cin >> choose;
if(choose != 1&& choose != 2 && choose != 3 && choose !=4 && choose != 5 && choose !=6 && choose !=7&&choose != 8)
{
cout << "输入错误:"<<endl;
}
else
{
switch(choose)
{
case 1:
int n;
do
{
fflush(stdin);
cout << "请确定要添加几个联系人:";
cin >> n;
}while(n <= 0);
head = AddContaxt(n);
break;
case 2:
system("CLS");
head = InsertCon(head);
break;
case 3:
head = FindCon(head);
break;
case 6:
system("CLS");
showmessage(head);
break;
case 7:
exit(0);
break;
case 4:
system("CLS");
AmendMessage(head);
break;
case 5:
system("CLS");
DeleteMessage(head);
break;
case 8:
system("CLS");
head = saveFileCONT(head );
break;
case 9:
// head = readFileCONT(head);
default:
system("CLS");
cout << "你输入错误,请重新选择!!!" << endl;
break;
}
}
}while(choose != 1&& choose != 2 && choose != 3 && choose !=4 && choose != 5 && choose !=6 && choose !=7);
return choose;
}
//添加联系人
CONT *AddContaxt(int n)
{
CONT *p,*q,*head;
int i;
system("CLS");
p = (CONT *)malloc(sizeof(CONT));
cout << "开始添加联系人信息:"<< endl;
cout << "输入姓名:";
cin >> p->name;
cout << "输入姓别:";
cin >> p->sex ;
cout << "输入班级:";
cin >> p->Class ;
cout << "输入住址:";
cin >> p->Adrre ;
cout << "输入手机号:";
cin >> p->Mobi ;
cout << "输入qq号:";
cin >> p->qq ;
head = p;
for(i = 2;i <= n;i++)
{
q = (CONT *)malloc(sizeof(CONT));
p->next = q ;
p = q;
system("CLS");
cout<< "总共需要输入"<< n << "个联系人的信息,"<<"现在你已输入" << i-1<< "个联系人信息."<< endl<< "请继续输入第"<<i << "个人的信息!!"<< endl;
cout << "输入姓名:";
cin >> p->name;
cout << "输入姓别:";
cin >> p->sex ;
cout << "输入班级:";
cin >> p->Class ;
cout << "输入住址:";
cin >> p->Adrre ;
cout << "输入手机号:";
cin >> p->Mobi ;
cout << "输入qq号:";
cin >> p->qq ;
}
p->next = NULL;
return head;
}
//插入联系人信息
CONT *InsertCon(CONT *head)
{
CONT *pc,*p,*q;
int choose ;
char name[10];
if(head ==NULL)
{
cout << "还没有添加任何联系人,请先添加联系人!!"<< endl;
return head;
}
pc = (CONT *)malloc(sizeof(CONT));
cout << "请依次输入被插入人的信息:姓名 /性别/班级/住址/手机号/qq号"<< endl;
cin >> pc->name >> pc->sex >> pc->Class >> pc->Adrre >> pc->Mobi >> pc->qq ;
pc ->next = NULL;
cout << "请选择自己喜欢的插入方式: "<< endl<< "1 插入在自己喜欢的人之前"<< endl << "2 插入在最后" << endl << "3 插入在开头" << endl;
do {
cin >> choose;
switch(choose)
{
case 1:
cout << "请输入自己喜欢的人的名字:";
cin >> name ;
if(strcmp(head->name ,name)==0)
{
pc->next = head;
head = pc;
return head;
}
else
{
q = head;
p = head->next ;
while(strcmp(p->name,name)!=0 && p->next !=NULL)
{
q = p;
p = p->next ;
}
if(strcmp(p->name ,name)==0)
{
pc->next = p ;
q = pc;
return head;
}
else
{
p->next = pc;
return head;
}
}
break;
case 2:
//cout << "请输入自己喜欢的人的名字:";
//cin >> name ;
p = head;
while(p->next != NULL)
p = p->next ;
p->next = pc;
return head;
break;
case 3:
//cout << "请输入自己喜欢的人的名字:";
//cin >> name ;
pc->next = head;
head = pc;
return head;
break;
default :
cout<<"error"<< endl;
break;
}
}while(choose!=1 &&choose != 2 && choose != 3);
}
//查找联系人信息
CONT *FindCon(CONT *head)
{
system("CLS");
char na[20];
CONT *p,*q;
if(head == NULL)
{
cout << "没有任何信息可查找,请先添加信息!!"<< endl;
return head;
}
cout << "请您输入要查找人的姓名:"<< endl;
cin >> na;
p = head;
while(p!= NULL)
{
if(strcmp(p->name ,na)==0)
{
q = p;
cout << "找到联系人,信息如下!!"<< endl;
cout << "姓名:" << q->name <<" 性别: " << q->sex << q->Class <<" 住址: " <<q->Adrre <<" 手机号: " <<q->Mobi <<" qq号: "
<< q->qq << endl;
break;
}
else
p = p->next ;
}
return head;
}
//修改联系人信息
CONT *AmendMessage(CONT *head)
{
CONT *p;
char nam[10];
char sex[5];
char Adrre[50];
char Class[20];
char Mobi[20];
char qq[10];
if(head == NULL)
{
cout<< "没有任何信息,请返回添加信息!!!"<< endl;
return head;
}
else
p = head;
cout << "请你输入要修改人的名字:";
cin >> nam;
while(p != NULL && p->name != nam)
{
if(strcmp(p->name ,nam)==0)
{
strcpy(p->name ,nam);
int choose;
do
{
cout << "请选择要修改哪一项的信息!!!"<< endl;
cout << "1 修改性别 2 修改班别 3 修改地址 4 修改手机号码 5 修改qq号 " << endl;
cin >> choose;
switch(choose)
{
case 1:
cout << "请输入要修改后的性别:";
cin >> sex;
strcpy(p->sex , sex);
cout << "修改成功!!!"<< endl;
system("CLS");
return head;
break;
case 2:
cout << "请输入修改后的班别:";
cin >> Class;
strcpy(p->Class ,Class);
system("CLS");
cout << "修改成功!!!"<< endl;
return head;
break;
case 3:
cout << " 请输入修改后的地址:";
cin >> Adrre;
strcpy(p->Adrre ,Adrre);
system("CLS");
cout << "修改成功!!!"<< endl;
return head;
break;
case 4:
cout << "请输入修改后的手机号码:";
cin >> Mobi;
strcpy(p->Mobi ,Mobi);
system("CLS");
cout << "修改成功!!!"<< endl;
return head;
break;
case 5:
cout << "请输入修改后的qq号:";
cin >> qq;
strcpy(p->qq ,qq);
system("CLS");
cout << "修改成功!!!"<< endl;
return head;
break;
default:
cout << "输入错误,重新选择!!" << endl;
break;
}
}while(choose != 0);
}
else if(p->next != NULL && p->name != nam)
{
p = p->next ;
}
else
{
cout << "输入名字错误,请重新选择4修改!!!" << endl;
return head;
}
}
//return head;
}
//删除联系人
CONT *DeleteMessage(CONT *head)
{
CONT *p,*q,*t;
char name[20];
char elem[10];
cout << "请输入要删除联系人的姓名:";
cin >> name;
if(head == NULL)
{
cout << "没有任何信息可删除,请添加信息!!"<< endl;
return head;
}
else if(strcmp(head->name,name)==0 )
{
t = head;
head = head->next ;
return head;
}
else
{
p = head->next ;
q = head;
}
while(p !=NULL && p->name != name)
{
q = p;
p = p->next ;
}
if(strcmp(p->name ,name)==0)
{
q->next = p->next ;
free(p);
//t = p;
}
else
{
cout<< "表中无该元素!" << endl;
return head;
}
if(t)
{
// elem = t->name ;
free(t);
}
return head;
}
//保存文件
CONT *saveFileCONT(CONT *head )
{
char *fileName;
FILE *fp;
CONT *p;
p = (CONT *)malloc(sizeof(CONT));
if(p=NULL)
{
cout <<"分配内存失败"<< endl;
// exit(0);
}
if(head ==NULL)
{
cout <<"没有任何信息,请先添加信息!!"<< endl;
return head;
}
else
{
p = head;
fileName = (char *)malloc(sizeof(char));
cout << "请输入文件名:" << endl;
cin >> fileName;
fileName = strcat(fileName,".txt");
if( (fp = fopen(fileName,"a")) == NULL)
cout << "can't open file" << endl;
do
{
//fwrite(head,sizeof(CONT),1,fp);
//fprintf(fp,p->name,p->sex,p->Class,p->Adrre,p->Mobi,p->qq );
fprintf(fp," 姓名:");
fprintf(fp, p->name );
fprintf(fp," 性别:");
fprintf(fp, p->sex);
fprintf(fp," 班别:");
fprintf(fp, p->Class);
fprintf(fp," 地址:");
fprintf(fp, p->Adrre);
fprintf(fp," 手机号:");
fprintf(fp, p->Mobi);
fprintf(fp," qq号:");
fprintf(fp, p->qq);
fprintf(fp,"\n");
cout << endl;
cout << "--------------------------------------------------------------------------------";
cout << " "<<"姓名:" <<p->name <<" 性别:" <<p->sex << " 班别:" <<p->Class <<" 住址:" <<p->Adrre <<"手机号:"
<< p->Mobi <<" qq号:" << p->qq << endl;
cout << "--------------------------------------------------------------------------------";
p=p->next ;
}while(p!=NULL);
}
fclose(fp);
return head;
}
//读取文件
CONT *readFileCONT(CONT *head)
{
char *fileName;
CONT *p;
FILE *fp;
fileName = (char *)malloc(sizeof(char));
cout << "请输入要打开的文件名:";
cin >> fileName;
fileName = strcat(fileName,".txt");
fp = fopen(fileName,"r");
if(fp == NULL)
{
cout << "文件没有任何信息,请先输入信息!!"<< endl;
}
else
{
while(!feof(fp))
{
p = (CONT *)malloc(sizeof(CONT));
if(p == NULL)
{
cout << "分配内存失败!!"<< endl;
return head;
}
fscanf(fp,p->name );
fscanf(fp,p->sex );
fscanf(fp,p->Class );
fscanf(fp,p->Adrre );
fscanf(fp,p->Mobi );
fscanf(fp,p->qq );
cout << "--------------------------------------------------------------------------------";
cout << " "<<"姓名:" <<p->name <<" 性别:" <<p->sex << " 班别:" <<p->Class <<" 住址:" <<p->Adrre <<"手机号:"
<< p->Mobi <<" qq号:" << p->qq << endl;
cout << "--------------------------------------------------------------------------------";
p->next = head;
head = p;
p = p->next ;
}
fclose(fp);
cout<< "读取信息成功!!!"<< endl;
}
fclose(fp);
return head;
}
void showmessage(CONT *head)
{
CONT *p;
int i=0;
if(head == NULL )
{
cout << "没有任何信息可输出,请添加信息!!!"<< endl;
}
else
{
p = head;
cout << "*******************************联系表如下***************************************";
do
{
i++;
cout << "--------------------------------------------------------------------------------";
cout << i << " "<<"姓名:" <<p->name <<" 性别:" <<p->sex << " 班别:" <<p->Class <<" 住址:" <<p->Adrre <<"手机号:"
<< p->Mobi <<" qq号:" << p->qq << endl;
cout << "--------------------------------------------------------------------------------";
p = p->next ;
}while(p!=NULL);
}
cout << "*********************************联系表***************************************";
cout << endl;
}
#include"stdafx.h"
using namespace std;
//结构体
struct contaxt
{
char name[10];
char sex[5];
char Adrre[50];
char Class[20];
char Mobi[20];
char qq[10];
struct contaxt *next;
};
//函数声明
typedef struct contaxt CONT;
CONT *InsertCon(CONT *head);
CONT *AddContaxt(int n);
CONT *FindCon(CONT *head);
CONT *AmendMessage(CONT *head);
CONT *DeleteMessage(CONT *head);
void showmessage(CONT *head);
int menu(CONT *head);
CONT *saveFileCONT(CONT *head );
CONT *readFileCONT(CONT *head);
int choose;
//入口
void main()
{
//system("color F4");
CONT *head;
head = NULL;
menu(head);
}
//系统主菜单
int menu(CONT *head)
{
cout << "请选择操作菜单!!!" << endl ;
do
{
cout << "---------------------------欢迎进入通讯录管理系统-------------------------------"
<< "---------------------------------操作菜单---------------------------------------";
cout << "--------------------------------------------------------------------------------"
<< " 1 添加联系人信息 "
<< " 2 插入联系人信息 " << endl
<< " 3 查找联系人信息 "
<< " 4 修改联系人信息 " << endl
<< " 5 删除联系人信息 "
<< " 6 显示联系人信息 " << endl
<< " 7 退出本系统 " << endl
<< " 8 保存文件 " << endl
<< " 9 读取文件 " << endl
<< "--------------------------------------------------------------------------------" << endl;
cout << "请选择操作菜单!!!" << endl ;
int choose;
//choose = getchar();
fflush(stdin);
//return choose;
cin >> choose;
if(choose != 1&& choose != 2 && choose != 3 && choose !=4 && choose != 5 && choose !=6 && choose !=7&&choose != 8)
{
cout << "输入错误:"<<endl;
}
else
{
switch(choose)
{
case 1:
int n;
do
{
fflush(stdin);
cout << "请确定要添加几个联系人:";
cin >> n;
}while(n <= 0);
head = AddContaxt(n);
break;
case 2:
system("CLS");
head = InsertCon(head);
break;
case 3:
head = FindCon(head);
break;
case 6:
system("CLS");
showmessage(head);
break;
case 7:
exit(0);
break;
case 4:
system("CLS");
AmendMessage(head);
break;
case 5:
system("CLS");
DeleteMessage(head);
break;
case 8:
system("CLS");
head = saveFileCONT(head );
break;
case 9:
// head = readFileCONT(head);
default:
system("CLS");
cout << "你输入错误,请重新选择!!!" << endl;
break;
}
}
}while(choose != 1&& choose != 2 && choose != 3 && choose !=4 && choose != 5 && choose !=6 && choose !=7);
return choose;
}
//添加联系人
CONT *AddContaxt(int n)
{
CONT *p,*q,*head;
int i;
system("CLS");
p = (CONT *)malloc(sizeof(CONT));
cout << "开始添加联系人信息:"<< endl;
cout << "输入姓名:";
cin >> p->name;
cout << "输入姓别:";
cin >> p->sex ;
cout << "输入班级:";
cin >> p->Class ;
cout << "输入住址:";
cin >> p->Adrre ;
cout << "输入手机号:";
cin >> p->Mobi ;
cout << "输入qq号:";
cin >> p->qq ;
head = p;
for(i = 2;i <= n;i++)
{
q = (CONT *)malloc(sizeof(CONT));
p->next = q ;
p = q;
system("CLS");
cout<< "总共需要输入"<< n << "个联系人的信息,"<<"现在你已输入" << i-1<< "个联系人信息."<< endl<< "请继续输入第"<<i << "个人的信息!!"<< endl;
cout << "输入姓名:";
cin >> p->name;
cout << "输入姓别:";
cin >> p->sex ;
cout << "输入班级:";
cin >> p->Class ;
cout << "输入住址:";
cin >> p->Adrre ;
cout << "输入手机号:";
cin >> p->Mobi ;
cout << "输入qq号:";
cin >> p->qq ;
}
p->next = NULL;
return head;
}
//插入联系人信息
CONT *InsertCon(CONT *head)
{
CONT *pc,*p,*q;
int choose ;
char name[10];
if(head ==NULL)
{
cout << "还没有添加任何联系人,请先添加联系人!!"<< endl;
return head;
}
pc = (CONT *)malloc(sizeof(CONT));
cout << "请依次输入被插入人的信息:姓名 /性别/班级/住址/手机号/qq号"<< endl;
cin >> pc->name >> pc->sex >> pc->Class >> pc->Adrre >> pc->Mobi >> pc->qq ;
pc ->next = NULL;
cout << "请选择自己喜欢的插入方式: "<< endl<< "1 插入在自己喜欢的人之前"<< endl << "2 插入在最后" << endl << "3 插入在开头" << endl;
do {
cin >> choose;
switch(choose)
{
case 1:
cout << "请输入自己喜欢的人的名字:";
cin >> name ;
if(strcmp(head->name ,name)==0)
{
pc->next = head;
head = pc;
return head;
}
else
{
q = head;
p = head->next ;
while(strcmp(p->name,name)!=0 && p->next !=NULL)
{
q = p;
p = p->next ;
}
if(strcmp(p->name ,name)==0)
{
pc->next = p ;
q = pc;
return head;
}
else
{
p->next = pc;
return head;
}
}
break;
case 2:
//cout << "请输入自己喜欢的人的名字:";
//cin >> name ;
p = head;
while(p->next != NULL)
p = p->next ;
p->next = pc;
return head;
break;
case 3:
//cout << "请输入自己喜欢的人的名字:";
//cin >> name ;
pc->next = head;
head = pc;
return head;
break;
default :
cout<<"error"<< endl;
break;
}
}while(choose!=1 &&choose != 2 && choose != 3);
}
//查找联系人信息
CONT *FindCon(CONT *head)
{
system("CLS");
char na[20];
CONT *p,*q;
if(head == NULL)
{
cout << "没有任何信息可查找,请先添加信息!!"<< endl;
return head;
}
cout << "请您输入要查找人的姓名:"<< endl;
cin >> na;
p = head;
while(p!= NULL)
{
if(strcmp(p->name ,na)==0)
{
q = p;
cout << "找到联系人,信息如下!!"<< endl;
cout << "姓名:" << q->name <<" 性别: " << q->sex << q->Class <<" 住址: " <<q->Adrre <<" 手机号: " <<q->Mobi <<" qq号: "
<< q->qq << endl;
break;
}
else
p = p->next ;
}
return head;
}
//修改联系人信息
CONT *AmendMessage(CONT *head)
{
CONT *p;
char nam[10];
char sex[5];
char Adrre[50];
char Class[20];
char Mobi[20];
char qq[10];
if(head == NULL)
{
cout<< "没有任何信息,请返回添加信息!!!"<< endl;
return head;
}
else
p = head;
cout << "请你输入要修改人的名字:";
cin >> nam;
while(p != NULL && p->name != nam)
{
if(strcmp(p->name ,nam)==0)
{
strcpy(p->name ,nam);
int choose;
do
{
cout << "请选择要修改哪一项的信息!!!"<< endl;
cout << "1 修改性别 2 修改班别 3 修改地址 4 修改手机号码 5 修改qq号 " << endl;
cin >> choose;
switch(choose)
{
case 1:
cout << "请输入要修改后的性别:";
cin >> sex;
strcpy(p->sex , sex);
cout << "修改成功!!!"<< endl;
system("CLS");
return head;
break;
case 2:
cout << "请输入修改后的班别:";
cin >> Class;
strcpy(p->Class ,Class);
system("CLS");
cout << "修改成功!!!"<< endl;
return head;
break;
case 3:
cout << " 请输入修改后的地址:";
cin >> Adrre;
strcpy(p->Adrre ,Adrre);
system("CLS");
cout << "修改成功!!!"<< endl;
return head;
break;
case 4:
cout << "请输入修改后的手机号码:";
cin >> Mobi;
strcpy(p->Mobi ,Mobi);
system("CLS");
cout << "修改成功!!!"<< endl;
return head;
break;
case 5:
cout << "请输入修改后的qq号:";
cin >> qq;
strcpy(p->qq ,qq);
system("CLS");
cout << "修改成功!!!"<< endl;
return head;
break;
default:
cout << "输入错误,重新选择!!" << endl;
break;
}
}while(choose != 0);
}
else if(p->next != NULL && p->name != nam)
{
p = p->next ;
}
else
{
cout << "输入名字错误,请重新选择4修改!!!" << endl;
return head;
}
}
//return head;
}
//删除联系人
CONT *DeleteMessage(CONT *head)
{
CONT *p,*q,*t;
char name[20];
char elem[10];
cout << "请输入要删除联系人的姓名:";
cin >> name;
if(head == NULL)
{
cout << "没有任何信息可删除,请添加信息!!"<< endl;
return head;
}
else if(strcmp(head->name,name)==0 )
{
t = head;
head = head->next ;
return head;
}
else
{
p = head->next ;
q = head;
}
while(p !=NULL && p->name != name)
{
q = p;
p = p->next ;
}
if(strcmp(p->name ,name)==0)
{
q->next = p->next ;
free(p);
//t = p;
}
else
{
cout<< "表中无该元素!" << endl;
return head;
}
if(t)
{
// elem = t->name ;
free(t);
}
return head;
}
//保存文件
CONT *saveFileCONT(CONT *head )
{
char *fileName;
FILE *fp;
CONT *p;
p = (CONT *)malloc(sizeof(CONT));
if(p=NULL)
{
cout <<"分配内存失败"<< endl;
// exit(0);
}
if(head ==NULL)
{
cout <<"没有任何信息,请先添加信息!!"<< endl;
return head;
}
else
{
p = head;
fileName = (char *)malloc(sizeof(char));
cout << "请输入文件名:" << endl;
cin >> fileName;
fileName = strcat(fileName,".txt");
if( (fp = fopen(fileName,"a")) == NULL)
cout << "can't open file" << endl;
do
{
//fwrite(head,sizeof(CONT),1,fp);
//fprintf(fp,p->name,p->sex,p->Class,p->Adrre,p->Mobi,p->qq );
fprintf(fp," 姓名:");
fprintf(fp, p->name );
fprintf(fp," 性别:");
fprintf(fp, p->sex);
fprintf(fp," 班别:");
fprintf(fp, p->Class);
fprintf(fp," 地址:");
fprintf(fp, p->Adrre);
fprintf(fp," 手机号:");
fprintf(fp, p->Mobi);
fprintf(fp," qq号:");
fprintf(fp, p->qq);
fprintf(fp,"\n");
cout << endl;
cout << "--------------------------------------------------------------------------------";
cout << " "<<"姓名:" <<p->name <<" 性别:" <<p->sex << " 班别:" <<p->Class <<" 住址:" <<p->Adrre <<"手机号:"
<< p->Mobi <<" qq号:" << p->qq << endl;
cout << "--------------------------------------------------------------------------------";
p=p->next ;
}while(p!=NULL);
}
fclose(fp);
return head;
}
//读取文件
CONT *readFileCONT(CONT *head)
{
char *fileName;
CONT *p;
FILE *fp;
fileName = (char *)malloc(sizeof(char));
cout << "请输入要打开的文件名:";
cin >> fileName;
fileName = strcat(fileName,".txt");
fp = fopen(fileName,"r");
if(fp == NULL)
{
cout << "文件没有任何信息,请先输入信息!!"<< endl;
}
else
{
while(!feof(fp))
{
p = (CONT *)malloc(sizeof(CONT));
if(p == NULL)
{
cout << "分配内存失败!!"<< endl;
return head;
}
fscanf(fp,p->name );
fscanf(fp,p->sex );
fscanf(fp,p->Class );
fscanf(fp,p->Adrre );
fscanf(fp,p->Mobi );
fscanf(fp,p->qq );
cout << "--------------------------------------------------------------------------------";
cout << " "<<"姓名:" <<p->name <<" 性别:" <<p->sex << " 班别:" <<p->Class <<" 住址:" <<p->Adrre <<"手机号:"
<< p->Mobi <<" qq号:" << p->qq << endl;
cout << "--------------------------------------------------------------------------------";
p->next = head;
head = p;
p = p->next ;
}
fclose(fp);
cout<< "读取信息成功!!!"<< endl;
}
fclose(fp);
return head;
}
void showmessage(CONT *head)
{
CONT *p;
int i=0;
if(head == NULL )
{
cout << "没有任何信息可输出,请添加信息!!!"<< endl;
}
else
{
p = head;
cout << "*******************************联系表如下***************************************";
do
{
i++;
cout << "--------------------------------------------------------------------------------";
cout << i << " "<<"姓名:" <<p->name <<" 性别:" <<p->sex << " 班别:" <<p->Class <<" 住址:" <<p->Adrre <<"手机号:"
<< p->Mobi <<" qq号:" << p->qq << endl;
cout << "--------------------------------------------------------------------------------";
p = p->next ;
}while(p!=NULL);
}
cout << "*********************************联系表***************************************";
cout << endl;
}
展开全部
/* HELLO.C -- Hello, world */
#include<stdio.h>
struct person
{
char name[8];
char tel[15];
char addr[50];
};
char filename[20]="E:\\txl.txt";
FILE *fp;
void creat();
void output();
void search();
void append();
void modify();
void delete();
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输出,请按5");
printf("\n\t\t退出,请按0\n");
printf("\n\t\t********************************************\n\n");
printf("Please select(0--5):");
scanf("%d",&m);
if(m>=0&&m<=5)
{
switch(m)
{
case 1: append();
break;
case 2: search();
break;
case 3: modify();
break;
case 4: delete();
break;
case 5: output();
break;
case 0: exit();
}
printf("\n\n操作完毕,请再次选择!");
}
else
printf("\n\n选择错误,请再次选择!");
}
}
/*输入模块creat( ): 创建通讯录的子函数。*/
void creat()
{
struct person one;
long s1;
/*printf("\n请输入通讯录文件名:");
scanf("%s",filename); */
if((fp=fopen(filename,"at+"))==NULL)
{
printf("\n不能建立通讯录!");
exit();
}
fprintf(fp,"%-10s%-20s%-50s\n","姓名","电话号码","住址");
printf("\n请输入姓名、电话号码及住址(以0结束)\n");
scanf("%s",one.name);
while(strcmp(one.name,"0"))
{
scanf("%s%s",one.tel,one.addr);
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
scanf("%s",one.name);
}
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;
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%-18s%-50s",one.name,one.tel,one.addr);
k=1;
}
}
if(!k)
printf("\n\n对不起,通讯簿中没有此人的记录。");
fclose(fp);
}
/*修改模块modify( ):在通讯录中修改某人通讯信息的子函数*/
void modify()
{
int m,k=0;
long offset;
char namekey[8];
struct person one;
printf("\n请输入姓名:");
scanf("%s",namekey);
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
while(!feof(fp))
{
offset=ftell(fp);
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
k=1;
break;
}
}
if(k)
{
printf("\n已查到,记录为:");
printf("\n%-10s%-18s%-50s",one.name,one.tel,one.addr);
printf("\n请输入新姓名、电话号码及住址:");
scanf("%s%s%s",one.name,one.tel,one.addr);
fseek(fp,offset,SEEK_SET);
printf("%ld",ftell(fp));
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
}
else
printf("\n对不起,通讯录中没有此人的记录。");
fclose(fp);
}
/*删除模块delete( ):在通讯录中删除某人通讯信息的子函数*/
void delete()
{
int m,k=0,flag;
long offset1,offset2;
char namekey[8], valid[4];
struct person one;
printf("\n请输入姓名:");
scanf("%s",namekey);
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
while(!feof(fp))
{
offset1=ftell(fp);
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
k=1;
break;
if(k)
{
printf("\n已查到,记录为");
printf("\n%-10s%-18s%-50s",one.name,one.tel,one.addr);
printf("\n确实要删除,按1;不删除,按0:");
scanf("%d",&m);
if(m)
{
fseek(fp,offset1,SEEK_SET);
fprintf(fp,"%-10s%-20s%-50s\n","","","");
}
else
printf("\n对不起,通讯录中没有此人的记录。");
fclose(fp);
}
}
}
}
<PIXTEL_MMI_EBOOK_2005>1###########################################################</PIXTEL_MMI_EBOOK_2005>
#include<stdio.h>
struct person
{
char name[8];
char tel[15];
char addr[50];
};
char filename[20]="E:\\txl.txt";
FILE *fp;
void creat();
void output();
void search();
void append();
void modify();
void delete();
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输出,请按5");
printf("\n\t\t退出,请按0\n");
printf("\n\t\t********************************************\n\n");
printf("Please select(0--5):");
scanf("%d",&m);
if(m>=0&&m<=5)
{
switch(m)
{
case 1: append();
break;
case 2: search();
break;
case 3: modify();
break;
case 4: delete();
break;
case 5: output();
break;
case 0: exit();
}
printf("\n\n操作完毕,请再次选择!");
}
else
printf("\n\n选择错误,请再次选择!");
}
}
/*输入模块creat( ): 创建通讯录的子函数。*/
void creat()
{
struct person one;
long s1;
/*printf("\n请输入通讯录文件名:");
scanf("%s",filename); */
if((fp=fopen(filename,"at+"))==NULL)
{
printf("\n不能建立通讯录!");
exit();
}
fprintf(fp,"%-10s%-20s%-50s\n","姓名","电话号码","住址");
printf("\n请输入姓名、电话号码及住址(以0结束)\n");
scanf("%s",one.name);
while(strcmp(one.name,"0"))
{
scanf("%s%s",one.tel,one.addr);
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
scanf("%s",one.name);
}
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;
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%-18s%-50s",one.name,one.tel,one.addr);
k=1;
}
}
if(!k)
printf("\n\n对不起,通讯簿中没有此人的记录。");
fclose(fp);
}
/*修改模块modify( ):在通讯录中修改某人通讯信息的子函数*/
void modify()
{
int m,k=0;
long offset;
char namekey[8];
struct person one;
printf("\n请输入姓名:");
scanf("%s",namekey);
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
while(!feof(fp))
{
offset=ftell(fp);
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
k=1;
break;
}
}
if(k)
{
printf("\n已查到,记录为:");
printf("\n%-10s%-18s%-50s",one.name,one.tel,one.addr);
printf("\n请输入新姓名、电话号码及住址:");
scanf("%s%s%s",one.name,one.tel,one.addr);
fseek(fp,offset,SEEK_SET);
printf("%ld",ftell(fp));
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
}
else
printf("\n对不起,通讯录中没有此人的记录。");
fclose(fp);
}
/*删除模块delete( ):在通讯录中删除某人通讯信息的子函数*/
void delete()
{
int m,k=0,flag;
long offset1,offset2;
char namekey[8], valid[4];
struct person one;
printf("\n请输入姓名:");
scanf("%s",namekey);
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
while(!feof(fp))
{
offset1=ftell(fp);
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
k=1;
break;
if(k)
{
printf("\n已查到,记录为");
printf("\n%-10s%-18s%-50s",one.name,one.tel,one.addr);
printf("\n确实要删除,按1;不删除,按0:");
scanf("%d",&m);
if(m)
{
fseek(fp,offset1,SEEK_SET);
fprintf(fp,"%-10s%-20s%-50s\n","","","");
}
else
printf("\n对不起,通讯录中没有此人的记录。");
fclose(fp);
}
}
}
}
<PIXTEL_MMI_EBOOK_2005>1###########################################################</PIXTEL_MMI_EBOOK_2005>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2016-06-06
展开全部
/* HELLO.C -- Hello, world */
#include<stdio.h>
struct person
{
char name[8];
char tel[15];
char addr[50];
};
char filename[20]="E:\\txl.txt";
FILE *fp;
void creat();
void output();
void search();
void append();
void modify();
void delete();
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输出,请按5");
printf("\n\t\t退出,请按0\n");
printf("\n\t\t********************************************\n\n");
printf("Please select(0--5):");
scanf("%d",&m);
if(m>=0&&m<=5)
{
switch(m)
{
case 1: append();
break;
case 2: search();
break;
case 3: modify();
break;
case 4: delete();
break;
case 5: output();
break;
case 0: exit();
}
printf("\n\n操作完毕,请再次选择!");
}
else
printf("\n\n选择错误,请再次选择!");
}
}
/*输入模块creat( ): 创建通讯录的子函数。*/
void creat()
{
struct person one;
long s1;
/*printf("\n请输入通讯录文件名:");
scanf("%s",filename); */
if((fp=fopen(filename,"at+"))==NULL)
{
printf("\n不能建立通讯录!");
exit();
}
fprintf(fp,"%-10s%-20s%-50s\n","姓名","电话号码","住址");
printf("\n请输入姓名、电话号码及住址(以0结束)\n");
scanf("%s",one.name);
while(strcmp(one.name,"0"))
{
scanf("%s%s",one.tel,one.addr);
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
scanf("%s",one.name);
}
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;
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%-18s%-50s",one.name,one.tel,one.addr);
k=1;
}
}
if(!k)
printf("\n\n对不起,通讯簿中没有此人的记录。");
fclose(fp);
}
/*修改模块modify( ):在通讯录中修改某人通讯信息的子函数*/
void modify()
{
int m,k=0;
long offset;
char namekey[8];
struct person one;
printf("\n请输入姓名:");
scanf("%s",namekey);
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
while(!feof(fp))
{
offset=ftell(fp);
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
k=1;
break;
}
}
if(k)
{
printf("\n已查到,记录为:");
printf("\n%-10s%-18s%-50s",one.name,one.tel,one.addr);
printf("\n请输入新姓名、电话号码及住址:");
scanf("%s%s%s",one.name,one.tel,one.addr);
fseek(fp,offset,SEEK_SET);
printf("%ld",ftell(fp));
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
}
else
printf("\n对不起,通讯录中没有此人的记录。");
fclose(fp);
}
/*删除模块delete( ):在通讯录中删除某人通讯信息的子函数*/
void delete()
{
int m,k=0,flag;
long offset1,offset2;
char namekey[8], valid[4];
struct person one;
printf("\n请输入姓名:");
scanf("%s",namekey);
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
while(!feof(fp))
{
offset1=ftell(fp);
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
k=1;
break;
if(k)
{
printf("\n已查到,记录为");
printf("\n%-10s%-18s%-50s",one.name,one.tel,one.addr);
printf("\n确实要删除,按1;不删除,按0:");
scanf("%d",&m);
if(m)
{
fseek(fp,offset1,SEEK_SET);
fprintf(fp,"%-10s%-20s%-50s\n","","","");
}
else
printf("\n对不起,通讯录中没有此人的记录。");
fclose(fp);
}
}
}
}
<PIXTEL_MMI_EBOOK_2005>1###########################################################</PIXTEL_MMI_EBOOK_2005>
另外,虚机团上产品团购,超级便宜
#include<stdio.h>
struct person
{
char name[8];
char tel[15];
char addr[50];
};
char filename[20]="E:\\txl.txt";
FILE *fp;
void creat();
void output();
void search();
void append();
void modify();
void delete();
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输出,请按5");
printf("\n\t\t退出,请按0\n");
printf("\n\t\t********************************************\n\n");
printf("Please select(0--5):");
scanf("%d",&m);
if(m>=0&&m<=5)
{
switch(m)
{
case 1: append();
break;
case 2: search();
break;
case 3: modify();
break;
case 4: delete();
break;
case 5: output();
break;
case 0: exit();
}
printf("\n\n操作完毕,请再次选择!");
}
else
printf("\n\n选择错误,请再次选择!");
}
}
/*输入模块creat( ): 创建通讯录的子函数。*/
void creat()
{
struct person one;
long s1;
/*printf("\n请输入通讯录文件名:");
scanf("%s",filename); */
if((fp=fopen(filename,"at+"))==NULL)
{
printf("\n不能建立通讯录!");
exit();
}
fprintf(fp,"%-10s%-20s%-50s\n","姓名","电话号码","住址");
printf("\n请输入姓名、电话号码及住址(以0结束)\n");
scanf("%s",one.name);
while(strcmp(one.name,"0"))
{
scanf("%s%s",one.tel,one.addr);
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
scanf("%s",one.name);
}
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;
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%-18s%-50s",one.name,one.tel,one.addr);
k=1;
}
}
if(!k)
printf("\n\n对不起,通讯簿中没有此人的记录。");
fclose(fp);
}
/*修改模块modify( ):在通讯录中修改某人通讯信息的子函数*/
void modify()
{
int m,k=0;
long offset;
char namekey[8];
struct person one;
printf("\n请输入姓名:");
scanf("%s",namekey);
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
while(!feof(fp))
{
offset=ftell(fp);
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
k=1;
break;
}
}
if(k)
{
printf("\n已查到,记录为:");
printf("\n%-10s%-18s%-50s",one.name,one.tel,one.addr);
printf("\n请输入新姓名、电话号码及住址:");
scanf("%s%s%s",one.name,one.tel,one.addr);
fseek(fp,offset,SEEK_SET);
printf("%ld",ftell(fp));
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
}
else
printf("\n对不起,通讯录中没有此人的记录。");
fclose(fp);
}
/*删除模块delete( ):在通讯录中删除某人通讯信息的子函数*/
void delete()
{
int m,k=0,flag;
long offset1,offset2;
char namekey[8], valid[4];
struct person one;
printf("\n请输入姓名:");
scanf("%s",namekey);
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\n不能打开通讯录!");
exit();
}
while(!feof(fp))
{
offset1=ftell(fp);
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
k=1;
break;
if(k)
{
printf("\n已查到,记录为");
printf("\n%-10s%-18s%-50s",one.name,one.tel,one.addr);
printf("\n确实要删除,按1;不删除,按0:");
scanf("%d",&m);
if(m)
{
fseek(fp,offset1,SEEK_SET);
fprintf(fp,"%-10s%-20s%-50s\n","","","");
}
else
printf("\n对不起,通讯录中没有此人的记录。");
fclose(fp);
}
}
}
}
<PIXTEL_MMI_EBOOK_2005>1###########################################################</PIXTEL_MMI_EBOOK_2005>
另外,虚机团上产品团购,超级便宜
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询