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.
pu36jnmwt/课程设计报告_c语言程序设计在线评判系统_计算机类18...

214 lines
5.1 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 <string.h>
#include<stdlib.h>
#include<conio.h>
void add();
void change();
void find();
void ioad();
void mune();
void see();
void save();
char n[30];
int k=0;
FILE *fp;
struct tong
{ int num;
char name[30]; //名字
char jiguan[30]; //籍贯
char handset[30]; //手机
char handset2[30];
char email[30]; //电子邮件
}m[15]={0};
void load()//录入
{ int i;
char s[100];
printf("请输入文件名");
scanf("%s",s);
fp=fopen(s,"r+");
if(fp==NULL)
{
printf("open error\n");
printf("请重新输入文件名");
load();
}
else
printf("录入成功\n");
for(i=0;i<15;i++)
{
fscanf(fp,"%d%s%s%s%s%s",&m[i].num,m[i].name,m[i].jiguan,m[i].handset,m[i].handset2,m[i].email);
}
printf("序号\t名字\t籍贯\t手机1\t手机2\t电子邮件\n");
for(i=0;i<15;i++)
{
printf("%d\t%s\t%s\t%s\t%s\t%s\n",m[i].num,m[i].name,m[i].jiguan,m[i].handset,m[i].handset2,m[i].email);
}
printf("按回车返回菜单");
fflush(stdin);
getchar();
mune();
}
void find()//寻找
{ int i;
printf("请输入要寻找的人的姓名\n");
fflush(stdin);
scanf("%s",n);
for(i=0;i<15;i++)
{
if (strcmp(m[i].name,n)==0)
break;
}
if(i>15)
{
printf("查无此人\n");
fflush(stdin);
getchar();
find();
}
printf("%d\t%s\t%s\t%s\t%s\t%s\n",m[i].num,m[i].name,m[i].jiguan,m[i].handset,m[i].handset2,m[i].email);
printf("按回车返回菜单");
fflush(stdin);
getchar();
mune();
}
void add()//添加
{int i;
printf("请输入要添加人的信息\n\t\t/姓名/籍贯/手机号1/手机号2/邮件\n");
scanf("%s%s%s%s%s",m[k].name,m[k].jiguan,m[k].handset,m[k].handset2,m[k].email);
k++;
m[k-1].num=k;
printf("输入1继续添加其它加回车返回菜单");
scanf("%d",&i);
if(i==1)
add();
mune();
}
void change()
{
char c;
int i;
printf("请输入要修改人的名字\n");
scanf("%s",n);
for(i=0;i<15;i++)
{
if(strcmp(m[i].name,n)==0)
break;
}
if(i>=15)
{
printf("无此人,请重输\n");
change();
getchar();
}
printf("序号\t名字\t籍贯\t手机1\t手机2\t电子邮件\n");
printf("%d\t%s\t%s\t%s\t%s\t%s\n",m[i].num,m[i].name,m[i].jiguan,m[i].handset,m[i].handset2,m[i].email);
printf("请输入修改后的信息\n");
printf("\t-----------确定要修改的信息------------\n");
printf("\t-----------名字扣1-----------\n");
printf("\t-----------籍贯扣2-----------\n");
printf("\t----------电话扣3----------\n");
printf("\t-----------电子邮件扣4-----------\n");
printf("\t--------------全部扣0------------\n");
getchar();
scanf("%c",&c);
switch(c)
{
case '1': printf("请输入姓名\n");scanf("%s",m[i].name);break;
case '2':printf("请输入籍贯\n");scanf("%s",m[i].jiguan);break;
case '3':printf("请输入电话1、2\n");scanf("%s%s",m[i].handset,m[i].handset2);break;
case '4':printf("请输入电子邮件\n");scanf("%s",m[i].email);break;
case '0':printf("请输入姓名、籍贯、电话1、2、电子邮件\n");scanf("%s%s%s%s%s",m[i].name,m[i].jiguan,m[i].handset,m[i].handset2,m[i].email);break;
default:printf("!!!!!!!!输入错误\n");
}
printf("按回车返回主页");
fflush(stdin);
getchar();
mune();
}
void see()
{ int i;
printf("序号\t名字\t籍贯\t手机1\t手机2\t电子邮件\n");
for(i=0;i<k;i++)
{
printf("%d\t%s\t%s\t%s\t%s\t%s\n",m[i].num,m[i].name,m[i].jiguan,m[i].handset,m[i].handset2,m[i].email);
}
printf("按回车键返回主页");
fflush(stdin);
getchar();
mune();
}
void mune()//菜单
{
char c;
int i;
system("cls");
printf("\t-----------通讯录程序------------\n");
printf("\t-----------文件录入扣1-----------\n");
printf("\t-----------信息浏览扣2-----------\n");
printf("\t----------联系人搜索扣3----------\n");
printf("\t-----------信息修改扣4-----------\n");
printf("\t------------添加扣5------------\n");
printf("\t----------保存扣6----------\n");
printf("\t--------------退出扣0------------\n");
fflush(stdin);
printf("序号\t名字\t籍贯\t手机1\t手机2\t电子邮件\n");
for(i=0;i<k;i++)
{
printf("%d\t%s\t%s\t%s\t%s\t%s\n",m[i].num,m[i].name,m[i].jiguan,m[i].handset,m[i].handset2,m[i].email);
}
scanf("%c",&c);
switch(c)
{
case '1':system("color 2E");
load();break;
case '2':see();break;
case '3':find();break;
case '4':change();break;
case '5':add();break;
case '6':save();break;
case '0':exit(0);
default:printf("!!!!!!!!输入错误,按回车重输\n");
fflush(stdin);
getchar();
}
}
int main(void)
{
int i;
system("cls");
system("color 3E");
fp=fopen("通讯录2.txt","r+");
if(fp==NULL)
{
printf("通讯录文件录入失败\n");
printf("请输入重新录入的文件\n");
load();
}
else
printf("通讯录录入成功请选择功能\n");
k=0;
for(i=0;i<15;i++)
{
fscanf(fp,"%d%s%s%s%s%s",&m[i].num,m[i].name,m[i].jiguan,m[i].handset,m[i].handset2,m[i].email);
if((m[i].num)!=0)
k++;
}
for(i=0;i<k;i++)
{
printf("%d\t%s\t%s\t%s\t%s\t%s\n",m[i].num,m[i].name,m[i].jiguan,m[i].handset,m[i].handset2,m[i].email);
}
printf("按回车键进入菜单");
fflush(stdin);
getchar();
mune();
}
void save()
{
int i;
rewind(fp);
for(i=0;i<k;i++)
fprintf(fp,"\n%d\t%s\t%s\t%s\t%s\t%s",m[i].num,m[i].name,m[i].jiguan,m[i].handset,m[i].handset2,m[i].email);
mune();
}