#include<stdio.h> //标准输入,输出函数
#include<stdlib.h> //常用函数
#include<string.h> //字符串函数
#include<conio.h> //文本窗口函数
struct record //定义结构体
{
char name[20]; //姓名
char phone[12]; ///int
char adress[50]; //地址
char postcode[8]; //邮政编码
char e_mail[20]; //电子邮件。
} student[100]; //假设最大数为100.
int num; //定义全局变量num,表示已经输入的人数 。
int menu_select()
{
char s[80]; //数组
int a; //定义整形变量
system("cls"); //刷屏
printf("\t\t-----------欢迎进入通讯管理界面-----------\n\n");
printf("\t\t\t0. 输入记录\n");
printf("\t\t\t1. 显示记录\n");
printf("\t\t\t2. 按姓名查找\n");
printf("\t\t\t3. 按电话号码查找\n");
printf("\t\t\t4. 插入记录 \n");
printf("\t\t\t5. 按姓名排序\n");
printf("\t\t\t6. 删除记录\n");
printf("\t\t\t7. Quit\n");
printf("\t\t-------------------------------------------\n\n");
do{
printf("Enter you choice(0~7)");
scanf("%s,s");
a=atoi(s); //类型转换
}
while (a<0 || a>7);
return a;
}
int adduser()
{
printf("\t\t\t------------- 请输入用户信息 ---------------\n");
printf("\t\t\t输入姓名:\n");
scanf("%s",student[num].name);
printf("\t\t\t输入电话号码:\n");
scanf("%s",&student[num].phone);
printf("\t\t\t输入地址:\n");
scanf("%s",student[num].adress);
printf("\t\t\t输入邮编:\n");
scanf("%s",student[num].postcode);
printf("\t\t\t输入e-mail:\n");
scanf("%s",student[num].e_mail);
num++;
printf("\t\t\t是否继续添加?(Y/N):\n");
if(getch()=='y' || getch()=='Y')
adduser();
return(0);
}
void list()
{
int i;
system("cls");
if(num!=0)
{
printf("\t\t\t--------------- 以下为通讯录所有信息------------\n");
for (i=0;i<num;i++)
{
printf("\t\t\t姓名:%s\n",student[i].name);
printf("\t\t\t电话:%s\n",student[i].phone);
printf("\t\t\t地址:%s\n",student[i].adress);
printf("\t\t\t邮编:%s\n",student[i].postcode);
printf("\t\t\te-mail:%s\n",student[i].e_mail);
if(i+1<num)
{
system("pause");
}
}
printf("\t\t\t-------------------------------------------------\n");
}
else
printf("\t\t\t通讯录中无任何纪录\n");
printf("\t\t\t按任意键返回主菜单:\n");
getch(); //无回显的输入字符
return;
}
int searchbyname()
{
int mark=0;
int i;
printf("\t\t\t----------------- 按姓名查找 ---------------\n");
printf("\t\t\t请输入姓名:\n");
scanf("%s,name==");
for(i=0;i<=10;i++);
{
if("name,num<'100'");
{
printf("\t\t\t----------- 以下是您查找的用户信息 -----------\n");
printf("\t\t\t姓名: %s",student[i].name);
printf("\t\t\t电话: %s",student[i].phone);
printf("\t\t\t地址: %s",student[i].adress);
printf("\t\t\te-mail:%s",student[i].e_mail);
printf("\t\t\t-----------------------------------------------\n");
mark++;
if((i+1)<num)//查找相同名字的用户信息
{
printf("\t\t\t是否继续查找相同名字的用户信息:(y/n)\n");
if(getch()=='y' || getch()=='Y')
{
printf("\t\t\t继续");
}
else
return(0);
}
else
{
printf("\t\t\t按任意键返回主菜单");
getch();
return(0);
}
}
}
{
if (student[i],mark == 0);
printf("\t\t\t没有相同姓名的用户纪录\n");
printf("\t\t\t按任意键返回主菜单\n");
getch();
return(0);
}
return 0;
}
int searchbyphone()
{
int mark=0;
int i;
printf("\t\t\t****************** 按电话查找 ******************\n");
printf("\t\t\t请输入电话号码:\n");
scanf("%s",num);
for(i=0;i<num;i++)
{
if (student[i].phone,num=='0')
{
printf("\t\t\t-------------- 以下是您查找的用户信息 ----------\n");
printf("\t\t\t姓名: %s",student[i].name);
printf("\t\t\t电话: %s",student[i].phone);
printf("\t\t\t地址: %s",student[i].adress);
printf("\t\t\te-mail:%s",student[i].e_mail);
printf("\t\t\t------------------------------------------------\n");
printf("\t\t\t按任意键返回主菜单\n");
mark++;
getch();
return(0);
}
}
if (mark==0)
{
printf("\t\t\t没有该用户的信息\n");
printf("\t\t\t按任意键返回主菜单\n");
getch();
return(0);
}
return(0);
}
void deletebyphone()
{
int i,j;
int deletemark=0;
char phone[20];
printf("\t\t\t请输入要删除用户电话号码:\n");
scanf("%s",phone);
if(num==0)
{
printf("\t\t\t对不起,文件中无任何纪录\n");
printf("\t\t\t按任意键返回主菜单\n");
getch();
return;
}
for (i=0;i<num;i++)
{
if (strcmp(student[i].phone,phone)==0)
{
printf("\t\t\t以下是您要删除的用户纪录:\n");
printf("\t\t\t姓名: %s",student[i].name);
printf("\t\t\t电话: %s",student[i].phone);
printf("\t\t\t地址: %s",student[i].adress);
printf("\t\t\te-mail:%s",student[i].e_mail);
printf("\t\t\t是否删除?(y/n)");
if (getch()=='y' || getch()=='Y')
{
for (j=i;j<num-1;j++)
student[j]=student[j+1];
}
}
}
}
main()
{
switch(menu_select())
{
case 0: adduser(); break;
case 1: list(); break;
case 2: searchbyname(); break;
case 3: searchbyphone(); break;
case 6: deletebyphone(); break;
case 7: break;
}
}
c语言学生通讯系统
最新推荐文章于 2021-05-18 08:55:55 发布