thhird commit

master
parent dcc4004495
commit d97ab49c3a

@ -80,13 +80,91 @@ void add()
//ÐÞ¸Ä
void modify()
{
char namekey[8];
printf("输入要查询的姓名:");
scanf("%s",namekey);
if((fp=fopen("user.txt","ab+"))==NULL) //打开文件
{
printf("\n不能打开文件!\n");
exit(0);
}
int m=0,t=1;
while(!feof(fp))
{
fread(&user[m],sizeof(struct user),1,fp)==1; //读取结构体中一个用户信息
if(!strcmp(user[m].name,namekey)) //判断是否相同
{
t=0; //若相同则在后面if句中输出
break;
}
m++;
}
if(t)
printf("未找到\n"),fclose(fp),system("pause"),menu();
else
{
printf("找到\n");
printf("姓名\t\t籍贯\t\t电话1\t\t电话2\t\t邮箱\n");
printf("%-8s\t",user[m].name);
printf("%-15s\t",user[m].place);
printf("%-15s\t",user[m].tel1);
printf("%-15s\t",user[m].tel2);
printf("%-20s\t",user[m].email);
}
printf("\n您想要修改哪条信息?\n\n1.姓名\t2.籍贯\t3.电话1\t4.电话2\t5.邮箱\t其它任意键.不修改"); //修改信息提示
int a; //修改的信息序号
scanf("%d",&a);
char *newname;
char nweplace[15];
char newtel1[15];
char newtel2[15];
char newemail[20];
switch(a)
{
case 1:scanf("%s",newname),strcpy(user[m].name,newname),printf("%s",user[m].name);break;
default:break;
}
printf("修改成功\n");
fclose(fp);
system("pause");
menu();
}
//²éѯ
void search()
{
char namekey[8];
printf("输入要查询的姓名:");
scanf("%s",namekey);
if((fp=fopen("user.txt","r"))==NULL) //打开文件
{
printf("\n不能打开文件!\n");
exit(0);
}
int m=0,t=0;
while(!feof(fp))
{
fread(&user[m],sizeof(struct user),1,fp)==1; //读取结构体中一个用户信息
if(!strcmp(user[m].name,namekey)) //判断是否相同
{
t=1; //若相同则在后面if句中输出
break;
}
m++;
}
if(t)
{
printf("找到\n");
printf("姓名\t\t籍贯\t\t电话1\t\t电话2\t\t邮箱\n");
printf("%-8s\t",user[m].name);
printf("%-15s\t",user[m].place);
printf("%-15s\t",user[m].tel1);
printf("%-15s\t",user[m].tel2);
printf("%-20s\t",user[m].email);
}
else
printf("未找到\n");
fclose(fp);
system("pause");
menu();
}
//ä¯ÀÀ

Binary file not shown.
Loading…
Cancel
Save