You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

448 lines
8.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#include<conio.h>
#define N 15
char inform[1000];
struct person
{
char information[100];
}per[N];
int load()
{
FILE *fp;
int i,j,a=0;
fp=fopen("a.txt","r+");
if(fp==NULL)
{
printf("打开文件失败\n");
}
for(i=0,j=1;(!feof(fp))||(i>N);i++)
{
fgets(inform,1000,fp);
if(i>1)
{
strcpy(per[j].information,inform);
j++;
}
}
fclose(fp);
while((strcmp(per[a+1].information,"\0"))!=0&&(j<=N))
{
a=a+1;
}
return (a-1);
}
void printf_bangong(int p)
{
int n,m,i;
char a[6];
for(i=1;i<=p;i++)
{
for(n=0,m=56;n<6;n++,m++)
{
a[n]=per[i].information[m];
}
if((strcmp(a,"办公类")==0))
{
printf("%s",per[i].information);
}
}
}
void printf_geren(int p)
{
int n,m,i;
char a[6];
for(i=1;i<=p;i++)
{
for(n=0,m=56;n<6;n++,m++)
{
a[n]=per[i].information[m];
}
if((strcmp(a,"个人类")==0))
{
printf("%s",per[i].information);
}
}
}
void printf_shangwu(int p)
{
int n,m,i;
char a[6];
for(i=1;i<=p;i++)
{
for(n=0,m=56;n<6;n++,m++)
{
a[n]=per[i].information[m];
}
if((strcmp(a,"商务类")==0))
{
printf("%s",per[i].information);
}
}
}
int input(int n,int m)
{
int t=0;
FILE *fp;
fp=fopen("a.txt","a");
if((n+m)>15)
{
printf("通信录总录入信息不能超过15条请重新确定添加人数\n");
printf("函数的第一个参数为从编号几开始添加,函数第二个参数为需要添加的总人数,输入两个参数是注意空一格\n");
scanf("%d %d",&n,&m);
input(n,m);
}
if((m+n)<=15)
{
int i,j,k,y=0,t=0;
char s[100];
for(j=0;j<=m;j++)
{ if(t>0)
{
printf("请按以下顺序输入添加人信息\n");
printf("姓名 电话 邮箱 分类\n");
}
fgets(s,100,stdin);
for(i=18,k=9;k<20;i++,k++)
{
if(per[j].information[i]==s[k])
{
y=y+1;
}
}
if(y==19)
{
printf("您添加的联系人重复!已返回初始添加阶段!\n\n");
printf("请输入需要从编号几开始添加,以及需要添加的总人数,输入两个参数是注意空一格\n");
scanf("%d %d",&n,&m);
input(n,m);
}
if(y!=19)
{
if(t>0)
{
fprintf(fp," %d %s",n,s);
printf("添加成功!\n");
n=n+1;
}
t=t+1;
}
}
}
fclose(fp);
}
void chang(int p)
{
int i,l,r=0,h,k,t,g,m;
char s[6],b[6],x[100];
fgets(s,6,stdin);
printf("请输入您需要修改的用户的姓名:\n");
fgets(s,6,stdin);
for(i=1;i<=p;i++)
{
g=0;
for(t=0,l=9;t<6;t++,l++)
{
b[t]=per[i].information[l];
}
for(t=0,l=9;t<6;t++,l++)
{
if(s[t]==b[t])
{
g=g+1;
}
}
if(g!=5)
{
r=r+1;
}
if(g==5)
{
fgets(x,100,stdin);
printf("请按以下顺序修改信息,其中编号为:%d\n",i);
printf("编号 姓名 电话 邮箱 分类\n");
fgets(x,100,stdin);
strcpy(per[i].information,x);
FILE *fp;
fp=fopen("a.txt","w+");
fputs("*************** 手机通讯管理系统 ***************\n",fp);
fputs("编号 姓名 电话 邮箱 分类\n",fp);
fclose(fp);
fp=fopen("a.txt","a");
for(h=1;h<=p;h++)
{
fputs(per[h].information,fp);
}
fclose(fp);
printf("修改成功!\n");
}
}
if(r==p)
{
printf("通讯录中没有此人!\n");
}
}
void shancu(int p)
{
int i,l,r=0,h,k,t,g,m;
char s[6],b[6],x[100];
fgets(s,6,stdin);
printf("请输入您需要删除的用户的姓名:\n");
fgets(s,6,stdin);
for(i=1;i<=p;i++)
{
g=0;
for(t=0,l=9;t<6;t++,l++)
{
b[t]=per[i].information[l];
}
for(t=0,l=9;t<6;t++,l++)
{
if(s[t]==b[t])
{
g=g+1;
}
}
if(g!=5)
{
r=r+1;
}
if(g==5)
{
FILE *fp;
fp=fopen("a.txt","w+");
fputs("*************** 手机通讯管理系统 ***************\n",fp);
fputs("编号 姓名 电话 邮箱 分类\n",fp);
fclose(fp);
fp=fopen("a.txt","a");
char d='1';
for(h=1;h<=p;h++)
{ if(h!=i)
{
per[h].information[1]=d;
d=d+1;
fputs(per[h].information,fp);
}
}
fclose(fp);
printf("删除成功!\n");
}
}
if(r==p)
{
printf("通讯录中没有此人!\n");
}
}
void bohao(int p)
{
int i,l,j,r=0,h,k,t,g,m,y;
char s[6],b[6],x[100];
for(t=0,j=1;j<=p;t++,j++)
{
printf(per[j].information);
}
fgets(s,6,stdin);
printf("请输入您需要拨号的用户的姓名:\n");
fgets(s,6,stdin);
for(i=1;i<=p;i++)
{
g=0;
for(t=0,l=9;t<6;t++,l++)
{
b[t]=per[i].information[l];
}
for(t=0,l=9;t<6;t++,l++)
{
if(s[t]==b[t])
{
g=g+1;
}
}
if(g!=5)
{
r=r+1;
}
if(g==5)
{
for(y=18;y<29;y++)
{
printf("%c",per[i].information[y]);//打印一个数字
printf("");//响铃一次
Sleep(500);//延时0.5秒
}
}
if(r==p)
{
printf("通讯录中没有此人!\n");
}
}
}
int menu_select()
{
int p,n,m,c;
char s,k;
system("cls");
printf("\t\t *****手机通讯录管理系统***** \n");
printf("\t\t\t 1.查看功能\n");
printf("\t\t\t 2.增加功能\n");
printf("\t\t\t 3.拨号功能\n");
printf("\t\t\t 4.修改功能\n");
printf("\t\t\t 5.删除功能\n");
printf("\t\t\t 6.退出系统\n");
printf("\t\t\t 请您选择1-6)");
scanf("%d",&c);
p=load();
printf("%d",p);
switch(c)
{
case 1:scanf("%c",&s);
printf("请选择您需要查看的类别A-CA 办公类 B 个人类 C 商务类\n");
scanf("%c",&s);
if(s=='A')
{
printf_bangong(p);
scanf("%c",&k);
printf("\n按0返回主菜单按其他任意键退出系统\n");
scanf("%c",&k);
if(k=='0')
{
menu_select();
}
}
if(s=='B')
{
printf_geren(p);
scanf("%c",&k);
printf("\n按0返回主菜单按其他任意键退出系统\n");
scanf("%c",&k);
if(k=='0')
{
menu_select();
}
}
if(s=='C')
{
printf_shangwu(p);
scanf("%c",&k);
printf("\n按0返回主菜单按其他任意键退出系统\n");
scanf("%c",&k);
if(k=='0')
{
menu_select();
}
}
else
{
printf("您输入的选项有误,已返回主菜单,请重新选择!");
scanf("%c",&k);
if(k=='0')
{
menu_select();
}
printf("\n按0返回主菜单按其他任意键退出系统\n");
k=getchar();
if(k=='0')
{
menu_select();
}
scanf("%c",&k);
if(k=='0')
{
menu_select();
}
scanf("%c",&k);
scanf("%c",&k);
if(k=='0')
{
menu_select();
}
if(k=='0')
{
menu_select();
}
}
break;
case 2:
printf("请输入需要从编号几开始添加,以及需要添加的总人数,输入两个参数是注意空一格\n");
printf("当前文件中总人数为:%d\n",p);
scanf("%d %d",&n,&m);
input(n,m);
printf("\n按0返回主菜单按其他任意键退出系统\n");
scanf("%c",&k);
if(k=='0')
{
menu_select();
}
break;
case 3:bohao(p);
scanf("%c",&k);
printf("\n按0返回主菜单按其他任意键退出系统\n");
k=getchar();
if(k=='0')
{
menu_select();
}
scanf("%c",&k);
scanf("%c",&k);
if(k=='0')
{
menu_select();
}
break;
case 4:chang(p);
printf("\n按0返回主菜单按其他任意键退出系统\n");
scanf("%c",&k);
if(k=='0')
{
menu_select();
}
case 5:shancu(p);
printf("\n按0返回主菜单按其他任意键退出系统\n");
k=getchar();
if(k=='0')
{
menu_select();
}
scanf("%c",&k);
if(k=='0')
{
menu_select();
}
scanf("%c",&k);
if(k=='0')
{
menu_select();
}
break;
}
}
void solve()
{
FILE *fp;
fp=fopen("a.txt","w");
if(fp==NULL)
{
printf("打开文件失败\n");
}
if(fp!=NULL)
{
fprintf(fp,"*************** 手机通讯管理系统 ***************\n");
fprintf(fp,"编号 姓名 电话 邮箱 分类\n");
fprintf(fp," 1 李鑫 15383997816 1819646867@qq.com 商务类\n");
fprintf(fp," 2 方诺基 15017816489 2819486478@qq.com 办公类\n");
fprintf(fp," 3 郑恩泽 18786134851 1817566135@qq.com 个人类\n");
}
fclose(fp);
}
int main(void)
{
solve();
menu_select();
}