代码如下:
#include<stdio.h>
#include<windows.h>
#include<stdlib.h>
#include<string.h>
#define LEN sizeof(struct xinxi)
int n;
struct xinxi
{
char number[5];
char name[15];
char telephone[11];
char QQnumber[10];
char email[30];
struct xinxi *next;
};
struct xinxi *head;
struct xinxi *p1,*p2,*p;
struct xinxi ch[1000000];
char p_mulu()
//目录界面
{
printf("*******************************************************************************\n");
printf("*
*\n");
printf("*
*\n");
printf("*
先生/女士----------您好
*\n");
printf("*
*\n");
printf("*
欢迎使用本通讯录系统。由于本人能力有限,对您造成的不便之处,请谅解。
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
█ 如若您想添加联系人信息,请按1;
*\n");
printf("*
*\n");
printf("*
█ 如若您想查看已有联系人信息 ,请按2;
*\n");
printf("*
*\n");
printf("*
█ 如若您想搜索联系人信息,请按3;
*\n");
printf("*
*\n");
printf("*
█ 如若您想修改联系人信息,请按4;
*\n");
printf("*
*\n");
printf("*
█ 退出本程序,请按5;
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*******************************************************************************\n");
char a;
printf("请输入您的选择:");
scanf("%c",&a);
system("cls");
return (a);
}
void creat(void)
{
n=0;
//char b;
FILE * fp;
/*printf("*******************************************************************************\n");
printf("*
*\n");
printf("*
*\n");
printf("*
是否储存已有文件?
*\n");
printf("*
*\n");
printf("*
(Y/N)
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*******************************************************************************\n");
printf("%c请输入您的选择%c:",1,1);
for(scanf("%c",&b);b=='Y'||b=='y'||b=='N'||b=='n';scanf("%c",&b))
{
if(b=='Y'||b=='a')
fp=fopen("a.txt","r");
else if(b=='N'||b=='n')
fp=fopen("a.txt","w");
else
p_jinggao();
system("cls");
getchar();
}*/
fp=fopen("a.txt","a+");
char a;
head=(struct xinxi*)malloc(LEN);
p1=(struct xinxi*)malloc(LEN);
head->next=p1;
p1->next = NULL;
while(1)
{
p2=(struct xinxi*)malloc(LEN);
printf("*******************************************************************************\n");
printf("*
*\n");
printf("*
请在下面添加联系人信息
*\n");
printf("*
*\n");
printf("*
联系人编号:
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*******************************************************************************\n");
printf("请输入联系人编号:");
scanf("%s",p1->number);
fprintf(fp,"%s ",p1->number);
system("cls");
printf("*******************************************************************************\n");
printf("*
*\n");
printf("*
请在下面添加联系人信息
*\n");
printf("*
*\n");
printf("*
联系人编号:%-15s
*\n",p1->number);
printf("*
联系人姓名:
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*******************************************************************************\n");
printf("请输入联系人姓名:");
scanf("%s",p1->name);
fprintf(fp,"%s ",p1->name);
system("cls");
printf("*******************************************************************************\n");
printf("*
*\n");
printf("*
请在下面添加联系人信息
*\n");
printf("*
*\n");
printf("*
联系人编号:%-15s
*\n",p1->number);
printf("*
联系人姓名:%-10s
*\n",p1->name);
printf("*
联系人手机号码:
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*******************************************************************************\n");
printf("请输入联系人手机号码:");
scanf("%s",p1->telephone);
fprintf(fp,"%s ",p1->telephone);
system("cls");
printf("*******************************************************************************\n");
printf("*
*\n");
printf("*
请在下面添加联系人信息
*\n");
printf("*
*\n");
printf("*
联系人编号:%-15s
*\n",p1->number);
printf("*
联系人姓名:%-10s
*\n",p1->name);
printf("*
联系人手机号码:%-11s
*\n",p1->telephone);
printf("*
联系人QQ号码:
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*******************************************************************************\n");
printf("请输入联系人QQ号码:");
scanf("%s",p1->QQnumber);
fprintf(fp,"%s ",p1->QQnumber);
system("cls");
printf("*******************************************************************************\n");
printf("*
*\n");
printf("*
请在下面添加联系人信息
*\n");
printf("*
*\n");
printf("*
联系人编号:%-15s
*\n",p1->number);
printf("*
联系人姓名:%-10s
*\n",p1->name);
printf("*
联系人手机号码:%-11s
*\n",p1->telephone);
printf("*
联系人QQ号码:%-10s
*\n",p1->QQnumber);
printf("*
联系人邮箱:
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*******************************************************************************\n");
printf("请输入联系人邮箱:");
scanf("%s",p1->email);
fprintf(fp,"%s\n",p1->email);
system("cls");
printf("*******************************************************************************\n");
printf("*
*\n");
printf("*
请在下面添加联系人信息
*\n");
printf("*
*\n");
printf("*
联系人编号:%-15s
*\n",p1->number);
printf("*
联系人姓名:%-10s
*\n",p1->name);
printf("*
联系人手机号码:%-11s
*\n",p1->telephone);
printf("*
联系人QQ号码:%-10s
*\n",p1->QQnumber);
printf("*
联系人邮箱:%-20s
*\n",p1->email);
printf("*
*\n");
printf("*
*\n");
printf("*
该联系人信息输入成功
*\n");
printf("*
继续输入请按'y'
*\n");
printf("*
停止输入请按'0'
*\n");
printf("*
*\n");
printf("*
*\n");
printf("*******************************************************************************\n");
p1->next = p2;
p2->next=NULL;
p1=p2;
printf("%c请输入您的选择%c:",1,1);
getchar();
scanf("%c",&a);
if(a=='0')break;
system("cls");
}
fclose(fp);
}
int main ()
//主函数
{
//
p_huanying();
//欢迎界面
{
for(;;)
{
char o;
o=p_mulu();
//目录界面
switch(o)
{
case'1':creat();break;
//case'2':chakan();break;
//case'3':sosuo();break;
//case'4':xiugai;break;
case'5':break;
//default:p_jinggao();break;
}
if (o=='5')
break;
}
}
//
p_jieshu();
//结束界面
return 0;
}