master
parent d276072d27
commit a8b22323d4

@ -1,16 +1,26 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <windows.h>
#pragma comment(lib, "Winmm.lib")
FILE *ptr1;
typedef struct
{
char name[20];
char phonenum[20];
int kind;
char email[30];
char email[50];
} lm;
lm linkman;
typedef struct
{
char user[20];
char pw[20];
int kind;
} User;
lm linkman,lkm;
User user;
int *offset;
void add();
void view();
@ -18,7 +28,9 @@ void search();
void sc();
void dial();
void amend();
void head();
void whattodo();
void zhuce();
int main_menu()
{
@ -26,18 +38,18 @@ int main_menu()
char c;
do{
system("cls");
printf("\t\t ════════════════\n");
printf("\t\t ══════════════════════════════\n");
printf("\t\t 手机通讯录小程序 \n");
printf("\t\t ════════════════\n");
printf("\t\t ┌────────────────\n");
printf("\t\t ══════════════════════════════\n");
printf("\t\t ┌────────────────────────────────\n");
printf("\t\t │ 1. 新增联系人 2. 全部联系人 │\n");
printf("\t\t │ │\n");
printf("\t\t │ 3. 查找联系人 4. 修改联系人 │\n");
printf("\t\t │ │\n");
printf("\t\t │ 5. 删除联系人 6. 拨号 │\n");
printf("\t\t │ 5. 设置用户 6. 拨号 │\n");
printf("\t\t │ │\n");
printf("\t\t │ 0. 退出程序 │\n");
printf("\t\t └────────────────\n");
printf("\t\t └────────────────────────────────\n");
printf("\t\t请您选择(0-6):");
c=getchar();
}while(c<'0'||c>'6');
@ -85,7 +97,7 @@ main()
}
void add()
{
int i=0;
int i=0,flag;
ptr1=fopen("storage.sto","rb+");
if(ptr1==NULL)
{
@ -100,9 +112,12 @@ void add()
while(!feof(ptr1))
{
fscanf(ptr1, "%s%s%d%s",linkman.name,linkman.phonenum,&linkman.kind,linkman.email);
++i;
//printf("%s\n",linkman.name);
i++;
}
if(ftell(ptr1)==0)i=0;
fseek(ptr1,0,SEEK_END);
printf("您目前有%d条联系人数据您还可以新增%d条联系人数据(%d/15)\n",i,15-i,i);
if(i==15)
{
@ -114,21 +129,45 @@ void add()
{
fflush(stdin);
++i;
pos_1:
printf("姓名:");
gets(linkman.name);
gets(lkm.name);
rewind(ptr1);
flag=0;
while(!feof(ptr1))
{
fscanf(ptr1, "%s%s%d%s",linkman.name,linkman.phonenum,&linkman.kind,linkman.email);
if(strcmp(linkman.name,lkm.name)==0)
{
printf("您输入的姓名和已有的记录相同,请重新输入\n");
goto pos_1;
}
}
pos_2:
printf("电话号码:");
gets(linkman.phonenum);
gets(lkm.phonenum);
rewind(ptr1);
while(!feof(ptr1))
{
fscanf(ptr1, "%s%s%d%s",linkman.name,linkman.phonenum,&linkman.kind,linkman.email);
if(strcmp(linkman.phonenum,lkm.phonenum)==0)
{
printf("您输入的电话号码和已有的记录相同,请重新输入\n");
goto pos_2;
}
}
printf("分类1 办公类 2 个人类 3 商务类):");
scanf("%d",&linkman.kind);
while(linkman.kind<0||linkman.kind>3)
scanf("%d",&lkm.kind);
while(lkm.kind<0||lkm.kind>3)
{
printf("请输入1-3内的数字");
scanf("%d",&linkman.kind);
scanf("%d",&lkm.kind);
}
printf("电子邮箱:");
fflush(stdin);
gets(linkman.email);
fprintf(ptr1, "%20s%20s%5d%20s",linkman.name,linkman.phonenum,linkman.kind,linkman.email);
printf("电子邮箱:");
gets(lkm.email);
fprintf(ptr1, "%20s%20s%5d%50s",lkm.name,lkm.phonenum,lkm.kind,lkm.email);
if(i<15)
printf("\n这是您的第%d条联系人您可以继续新增%d条联系人y/n",i,15-i);
else
@ -148,22 +187,14 @@ void view()
ptr1=fopen("storage.sto","rb+");
if(ptr1==NULL)
{
printf("您目前没有联系人的记录\n");
printf("【1】返回主目录\n");
printf("【2】新增联系人\n");
printf("【3】结束程序\n");
scanf("%d",&x);
while(x<1||x>3)
{
printf("请输入1-3内的数字");
scanf("%d",&x);
whattodo();
return;
}
switch(x)
fscanf(ptr1, "%s%s%d%s",linkman.name,linkman.phonenum,&linkman.kind,linkman.email);
if(ftell(ptr1)==0)
{
case 1:return;break;
case 2:add();return;break;
case 3:exit(0);
}
whattodo();
return;
}
rewind(ptr1);
fflush(stdin);
@ -177,23 +208,23 @@ void view()
printf("请输入1-4内的数字");
scanf("%d",&x);
}
printf("序号 姓名 手机号码 分类 电子邮件\n");
printf("***************************************************************\n");
head();//输出表头
if(x==1)
{
while(!feof(ptr1))
{
fscanf(ptr1, "%s%s%d%s",linkman.name,linkman.phonenum,&linkman.kind,linkman.email);
i++;
//printf("%d %-10s %-10s %d %-10s",i,linkman.name,linkman.phonenum,linkman.kind,linkman.email);
if(linkman.kind==1)
printf("%d %-10s %-10s 办公类 %-10s",i,linkman.name,linkman.phonenum,linkman.email);
printf("%2d %-10s %-20s 办公类 %-10s\n",++i,linkman.name,linkman.phonenum,linkman.email);
if(linkman.kind==2)
printf("%d %-10s %-10s 个人类 %-10s",i,linkman.name,linkman.phonenum,linkman.email);
printf("%2d %-10s %-20s 个人类 %-10s\n",++i,linkman.name,linkman.phonenum,linkman.email);
if(linkman.kind==3)
printf("%d %-10s %-10s 商务类 %-10s",i,linkman.name,linkman.phonenum,linkman.email);
printf("%2d %-10s %-20s 商务类 %-10s\n",++i,linkman.name,linkman.phonenum,linkman.email);
printf("\n");
}
}
@ -206,16 +237,17 @@ void view()
switch(x)
{
case 2:if(linkman.kind==1)printf("%d %-10s %-10s 办公类 %-10s",++i,linkman.name,linkman.phonenum,linkman.email);break;
case 3:if(linkman.kind==2)printf("%d %-10s %-10s 个人类 %-10s",++i,linkman.name,linkman.phonenum,linkman.email);break;
case 4:if(linkman.kind==3)printf("%d %-10s %-10s 商务类 %-10s",++i,linkman.name,linkman.phonenum,linkman.email);break;
case 2:if(linkman.kind==1)printf("%2d %-10s %-20s 办公类 %-10s\n",++i,linkman.name,linkman.phonenum,linkman.email);break;
case 3:if(linkman.kind==2)printf("%2d %-10s %-20s 个人类 %-10s\n",++i,linkman.name,linkman.phonenum,linkman.email);break;
case 4:if(linkman.kind==3)printf("%2d %-10s %-20s 商务类 %-10s\n",++i,linkman.name,linkman.phonenum,linkman.email);break;
}
printf("\n");
}
}
printf("已经显示全部内容,共%d条\n",i);
system("pause");
fclose(ptr1);
return;
}
void search()
@ -241,6 +273,12 @@ void search()
case 3:exit(0);
}
}
fscanf(ptr1, "%s%s%d%s",linkman.name,linkman.phonenum,&linkman.kind,linkman.email);
if(ftell(ptr1)==0)
{
whattodo();
return;
}
rewind(ptr1);
fflush(stdin);
printf("您想按照什么关键字搜索呢:\n");
@ -255,10 +293,12 @@ void search()
printf("请输入1-5内的数字");
scanf("%d",&x);
}
if(x==5)return;
char keywords[20];
fflush(stdin);
printf("请输入关键字:");
gets(keywords);
head();//输出表头
while(!feof(ptr1))
{
fscanf(ptr1, "%s%s%d%s",linkman.name,linkman.phonenum,&linkman.kind,linkman.email);
@ -284,23 +324,24 @@ void search()
{
switch(linkman.kind)
{
case 1:printf("%d %-10s%-10s办公类%-10s",++i,linkman.name,linkman.phonenum,linkman.email);break;
case 2:printf("%d %-10s%-10s个人类%-10s",++i,linkman.name,linkman.phonenum,linkman.email);break;
case 3:printf("%d %-10s%-10s商务类%-10s",++i,linkman.name,linkman.phonenum,linkman.email);break;
case 1:printf("%2d %-10s %-20s 办公类 %-10s\n",++i,linkman.name,linkman.phonenum,linkman.email);break;
case 2:printf("%2d %-10s %-20s 个人类 %-10s\n",++i,linkman.name,linkman.phonenum,linkman.email);break;
case 3:printf("%2d %-10s %-20s 商务类 %-10s\n",++i,linkman.name,linkman.phonenum,linkman.email);break;
}
}
u=0;
printf("\n");
}
printf("已经显示全部搜索结果,共%d条\n",i);
system("pause");
fclose(ptr1);
return;
}
void amend()
{
int x,i=0;
FILE *ptr2;
int x,i=0,flag,k,j,q;
lm array[15];
ptr1=fopen("storage.sto","rb+");
if(ptr1==NULL)
{
@ -321,39 +362,93 @@ void amend()
case 3:exit(0);
}
}
rewind(ptr1);
fscanf(ptr1, "%s%s%d%s",linkman.name,linkman.phonenum,&linkman.kind,linkman.email);
if(ftell(ptr1)==0)
{
whattodo();
return;
}
fflush(stdin);
printf("序号 姓名 手机号码 分类 电子邮件\n");
printf("***************************************************************\n");
head();//输出表头
i=0;
j=0;
rewind(ptr1);
while(!feof(ptr1))
{
fscanf(ptr1, "%s%s%d%s",linkman.name,linkman.phonenum,&linkman.kind,linkman.email);
i++;
//printf("%d %-10s %-10s %d %-10s",i,linkman.name,linkman.phonenum,linkman.kind,linkman.email);
if(linkman.kind==1)
printf("%d %-10s %-10s 办公类 %-10s",++i,linkman.name,linkman.phonenum,linkman.email);
if(linkman.kind==2)
printf("%d %-10s %-10s 个人类 %-10s",++i,linkman.name,linkman.phonenum,linkman.email);
if(linkman.kind==3)
printf("%d %-10s %-10s 商务类 %-10s",++i,linkman.name,linkman.phonenum,linkman.email);
printf("\n");
fscanf(ptr1, "%s%s%d%s",array[j].name,array[j].phonenum,&array[j].kind,array[j].email);
//printf("%2d %-10s %-20s 办公类 %-10s\n",++i,array[j].name,array[j].phonenum,array[j].email);
if(array[j].kind==1)
printf("%2d %-10s %-20s 办公类 %-10s\n",++i,array[j].name,array[j].phonenum,array[j].email);
if(array[j].kind==2)
printf("%2d %-10s %-20s 个人类 %-10s\n",++i,array[j].name,array[j].phonenum,array[j].email);
if(array[j].kind==3)
printf("%2d %-10s %-20s 商务类 %-10s\n",++i,array[j].name,array[j].phonenum,array[j].email);
j++;
}
printf("请从0-%d选择要修改的序号",%i);
printf("请从(1-%d选择要修改/删除的序号:",i);
scanf("%d",&x);
while(x<0||x>i)
{
printf("请从0-%d选择要修改的序号",%i);
fflush(stdin);
printf("请从1-%d选择要修改/删除的序号:",i);
scanf("%d",&x);
}
ptr2=fopen("temp","wb+");
if(ptr2==NULL)
q=i;//存储i的值;
printf("请问是要修改还是删除:\n【1】修改\n【2】删除\n");
scanf("%d",&flag);
while(flag<1||flag>2)
{
printf("ERROR");
exit(0);
printf("请重新输入1/2");
scanf("%d",&flag);
}
if(flag==2)goto pos_3;
//写入待修改的联系人信息
fflush(stdin);
printf("姓名:");
gets(array[x-1].name);
printf("电话号码:");
gets(array[x-1].phonenum);
printf("分类1 办公类 2 个人类 3 商务类):");
scanf("%d",&array[x-1].kind);
while(lkm.kind<0||lkm.kind>3)
{
printf("请输入1-3内的数字");
scanf("%d",&array[x-1].kind);
}
printf("电子邮箱:");
fflush(stdin);
gets(array[x-1].email);
pos_3:
i=0;
fclose(ptr1);
ptr1=fopen("storage.sto","wb");
i=0;
rewind(ptr1);
pos_4:
while(i<q)
{
if(x==(i+1)&&flag==2)
{
i++;continue;
}
fprintf(ptr1, "%20s%20s%5d%50s",array[i].name,array[i].phonenum,array[i].kind,array[i].email);
//printf("%20s%20s%5d%50s",array[i].name,array[i].phonenum,array[i].kind,array[i].email);
i++;
}
fclose(ptr1);
fflush(stdin);
printf("修改成功!\n");
system("pause");
return;
}
void sc()
@ -362,9 +457,98 @@ void sc()
}
void dial()
{
int x,i=0,flag,k,j,q;
lm array[15];
ptr1=fopen("storage.sto","rb+");
if(ptr1==NULL)
{
printf("您目前没有联系人的记录\n");
printf("【1】返回主目录\n");
printf("【2】新增联系人\n");
printf("【3】结束程序\n");
scanf("%d",&x);
while(x<1||x>3)
{
printf("请输入1-3内的数字");
scanf("%d",&x);
}
switch(x)
{
case 1:return;break;
case 2:add();return;break;
case 3:exit(0);
}
}
fscanf(ptr1, "%s%s%d%s",linkman.name,linkman.phonenum,&linkman.kind,linkman.email);
if(ftell(ptr1)==0)
{
whattodo();
return;
}
}
fflush(stdin);
head();//输出表头
i=0;
j=0;
rewind(ptr1);
while(!feof(ptr1))
{
fscanf(ptr1, "%s%s%d%s",array[j].name,array[j].phonenum,&array[j].kind,array[j].email);
//printf("%2d %-10s %-20s 办公类 %-10s\n",++i,array[j].name,array[j].phonenum,array[j].email);
if(array[j].kind==1)
printf("%2d %-10s %-20s 办公类 %-10s\n",++i,array[j].name,array[j].phonenum,array[j].email);
if(array[j].kind==2)
printf("%2d %-10s %-20s 个人类 %-10s\n",++i,array[j].name,array[j].phonenum,array[j].email);
if(array[j].kind==3)
printf("%2d %-10s %-20s 商务类 %-10s\n",++i,array[j].name,array[j].phonenum,array[j].email);
j++;
}
printf("请从1-%d选择要拨打的序号",i);
scanf("%d",&x);
while(x<0||x>i)
{
fflush(stdin);
printf("请从1-%d选择要拨打的序号",i);
scanf("%d",&x);
}
for(q=0;q<strlen(array[x-1].phonenum);q++)
{
printf("%c",array[x-1].phonenum[q]);
Sleep(600);
}
system("pause");
return;
}
void head()
{
printf("序号 姓名 手机号码 分类 电子邮件\n");
printf("***************************************************************************\n");
}
void whattodo()
{
int x;
printf("您目前没有联系人的记录\n");
printf("【1】返回主目录\n");
printf("【2】新增联系人\n");
printf("【3】结束程序\n");
scanf("%d",&x);
while(x<1||x>3)
{
printf("请输入1-3内的数字");
scanf("%d",&x);
}
switch(x)
{
case 1:return;break;
case 2:add();return;break;
case 3:exit(0);
}
}

Binary file not shown.

@ -1 +1 @@
中国电信 10000 1 10000@163.com 中国联通 10010 2 10010@126.com 中国移动 10086 3 10086@188.com 黄皓 13380341245 2 1374832868@qq.com 工大助手 88888888 1 8888@hut.aa
ÃÀ×Ì×Ì 133900 2 haibucuo@stu.hut.edu.cn
Loading…
Cancel
Save