📄 address_ list.c.txt
字号:
}/*结束 switch*/
}/*结束 while*/
}
void modif()
{
int n=0,i=0,found=0,exit=0,open;
FILE *fp;
char *nam="ssss",*s="ssss",*qq="qq";
struct record stu[N],p;
clrscr();
if((fp=fopen(fx_dir,"r+"))==NULL)
{cputs("不能打开.");
cprintf("记录数据在 "fx_dir);
cputs("确保退出文件!!! ");
cputs("按任意键继续");
getch();
found=0;
}
else open=1;
while(open==1&&!feof(fp)) /*Read file to stu[]*/
{
fread(&stu[n],sizeof(struct record),1,fp);
fgets(s,2,fp);
n++;
}
clrscr();
textbackground(7); textcolor(10);
while(exit==0)
{
gotoxy(1,1); cputs("1:输入名字修改");
gotoxy(1,2); cputs("2:输入QQ号修改");
gotoxy(1,3); cputs("3:退出");
gotoxy(3,4); cputs("请选择:");
gotoxy(19,4);
switch(getch())
{
case '1':
{found=0,i=0;
gotoxy(1,6);cputs("输入名字为查找");
gotoxy(23,6); gets(nam);
while(found==0&&i<n)
{
if(strcmp(stu[i].name,nam)==0)
{
found=1;
gotoxy(5,7); cputs("记录是:");
gotoxy(5,8); puts("姓名 :"); gotoxy(15,8); puts(stu[i].name);
gotoxy(5,9); puts("性别 :"); gotoxy(15,9); puts(stu[i].sex);
gotoxy(5,10); puts("地址 :"); gotoxy(15,10); puts(stu[i].address);
gotoxy(5,11); puts("电话号码:"); gotoxy(15,11); puts(stu[i].tel_num);
gotoxy(5,12); puts("生日 :"); gotoxy(15,12); puts(stu[i].bir_day);
gotoxy(5,13); puts("QQ号码 :"); gotoxy(15,13); puts(stu[i].qq);
gotoxy(5,14); puts("电子邮箱:"); gotoxy(15,14); gets(stu[i].e_mail);
gotoxy(6,15); cputs("输入你想要改的内容:");
gotoxy(1,16); cputs("姓名 :"); gotoxy(10,16); gets(stu[i].name);
gotoxy(1,17); cputs("性别 :"); gotoxy(10,17); gets(stu[i].sex);
gotoxy(1,18); cputs("地址 :"); gotoxy(10,18); gets(stu[i].address);
gotoxy(1,19); cputs("电话号码:"); gotoxy(10,19); gets(stu[i].tel_num);
gotoxy(1,20); cputs("生日 :"); gotoxy(10,20); gets(stu[i].bir_day);
gotoxy(1,21); cputs("QQ号码 :"); gotoxy(10,21); gets(stu[i].qq);
gotoxy(1,22); cputs("E_mail :"); gotoxy(10,22); gets(stu[i].e_mail);
}
i++;
} /*end search*/
if(found==0)
{
gotoxy(1,14);cputs("没有找到该同学");
cputs("按任意键继续");getch();clrscr();
}
else{
rewind(fp);
puts("修改了吗?,y/n?");
if(getch()=='y')
{
for(k=0;k<n-1;k++)
{ fwrite(&stu[k],sizeof(struct record),1,fp);
fputs("\n",fp);
}/*end for */
gotoxy(3,24);
puts("修改成功!!");
}/*end if*/
gotoxy(1,25);cputs("按任意键继续");
getch();clrscr();
}
}break; /*end case '1'*/
case '2':
{found=0,i=0;
gotoxy(1,6);cputs("输入QQ号码查找");
gotoxy(27,6); gets(qq);
while(found==0&&i<n)
{
if(strcmp(stu[i].qq,qq)==0)
{
found=1;
gotoxy(5,7); cputs("记录是:");
gotoxy(5,8); puts("姓名 :"); gotoxy(15,8); puts(stu[i].name);
gotoxy(5,9); puts("性别 :"); gotoxy(15,9); puts(stu[i].sex);
gotoxy(5,10); puts("地址 :"); gotoxy(15,10); puts(stu[i].address);
gotoxy(5,11); puts("电话号码:"); gotoxy(15,11); puts(stu[i].tel_num);
gotoxy(5,12); puts("生日 :"); gotoxy(15,12); puts(stu[i].bir_day);
gotoxy(5,13); puts("QQ号码 :"); gotoxy(15,13); puts(stu[i].qq);
gotoxy(5,14); puts("电子邮箱:"); gotoxy(15,14); gets(stu[i].e_mail);
gotoxy(5,15);cputs("输入你想要改的内容:");
gotoxy(1,16); cputs("姓名 :"); gotoxy(10,16); gets(stu[i].name);
gotoxy(1,17); cputs("性别 :"); gotoxy(10,17); gets(stu[i].sex);
gotoxy(1,18); cputs("地址 :"); gotoxy(10,18); gets(stu[i].address);
gotoxy(1,19); cputs("电话号码:"); gotoxy(10,19); gets(stu[i].bir_day);
gotoxy(1,20); cputs("生日 :"); gotoxy(10,20); gets(stu[i].bir_day);
gotoxy(1,21); cputs("QQ号码 :"); gotoxy(10,21); gets(stu[i].qq);
gotoxy(1,22); cputs("E_mail :"); gotoxy(10,22); gets(stu[i].e_mail);
}
i++;
} /*end search*/
if(found==0)
{
gotoxy(1,14);cputs("没有找到");
cputs("按任意键继续");getch();clrscr();
}
else{
rewind(fp);
gotoxy(5,23);cputs("确定修改吗,y/n?");
if(getch()=='y')
{
for(k=0;k<n-1;k++)
{ fwrite(&stu[k],sizeof(struct record),1,fp);
fputs("\n",fp);
}/*end for */
gotoxy(5,24); cputs("修改成功!!!");
gotoxy(1,25); cputs("按任意键继续");
getch();clrscr();
}
} break;/*end case '2'*/
case '3':{fclose(fp);exit=1;}break;
default :cputs("输入正确数据查找!");
}/*End switch*/
}/*end while*/
}
}
void insert()
{
char *s="fang xian";
int n=0;
FILE *fp;
struct record stu[N];
clrscr();
if((fp=fopen(fx_dir,"a+"))==NULL)
{cprintf("不能打开");getch();};
while(!feof(fp)) /*Read file to stu[]*/
{
fread(&stu[n],sizeof(struct record),1,fp);
fgets(s,2,fp);
n++;
}
clrscr();
textbackground(7); textcolor(15);
gotoxy(1,2); cputs("输入你想要添加的数据:");
gotoxy(1,5); cputs("姓名 :"); gotoxy(10,5); gets(stu[n-1].name);
gotoxy(1,6); cputs("性别 :"); gotoxy(10,6); gets(stu[n-1].sex);
gotoxy(1,7); cputs("地址 :"); gotoxy(10,7); gets(stu[n-1].address);
gotoxy(1,8); cputs("电话号码:"); gotoxy(10,8); gets(stu[n-1].tel_num);
gotoxy(1,9); cputs("生日 :"); gotoxy(10,9); gets(stu[n-1].bir_day);
gotoxy(1,10); cputs("QQ号码 :"); gotoxy(10,10); gets(stu[n-1].qq);
gotoxy(1,11); cputs("E_mail :"); gotoxy(10,11); gets(stu[n-1].e_mail);
fwrite(&stu[n-1],sizeof(struct record),1,fp);
fputs("\n",fp);
fclose(fp);
order();}
void dele()
{int n=0,i=0,found=0,exit=0;
FILE *fp;
char *name="nn",*s="ssss ";
char *qq="qq";
char *e_mail="ee";
struct record stu[N];
clrscr();
if((fp=fopen(fx_dir,"r+"))==NULL)
{cprintf("不能打开");getch();}
while(!feof(fp)) /*Read file to stu[]*/
{
fread(&stu[n],sizeof(struct record),1,fp);
fgets(s,2,fp);
n++;
}
clrscr();
textbackground(7); textcolor(9);
clrscr();
while(exit==0)
{
gotoxy(5,1); cputs("1: 按QQ号码删除");
gotoxy(5,2); cputs("2: 按姓名删除");
gotoxy(5,3); cputs("3: 按e_mail删除");
gotoxy(5,4); cputs("4: 退出");
gotoxy(5,5); cputs("请选择: ");
switch(getch())
{
case '1':
{found=0,i=0;
gotoxy(1,6);cputs("输入QQ 号码为删除");
gotoxy(23,6); gets(qq);
while(found==0&&i<n)
{
if(strcmp(stu[i].qq,qq)==0)
{
found=1;
gotoxy(5,7); cputs("记录是:");
gotoxy(5,8); puts("姓名 :"); gotoxy(15,8); puts(stu[i].name);
gotoxy(5,9); puts("性别 :"); gotoxy(15,9); puts(stu[i].sex);
gotoxy(5,10); puts("地址 :"); gotoxy(15,10); puts(stu[i].address);
gotoxy(5,11); puts("电话号码:"); gotoxy(15,11); puts(stu[i].tel_num);
gotoxy(5,12); puts("生日 :"); gotoxy(15,12); puts(stu[i].bir_day);
gotoxy(5,13); puts("QQ号码 :"); gotoxy(15,13); puts(stu[i].qq);
gotoxy(5,14); puts("电子邮箱:"); gotoxy(15,14); gets(stu[i].e_mail);
gotoxy(5,16);cputs("确定删除吗?");
rewind(fp); puts("确定删除吗,y/n?");
if(getch()=='y')
{
for(k=0;k<n-1;k++)
{ fwrite(&stu[k],sizeof(struct record),1,fp);
fputs("\n",fp);
}/*end for */
gotoxy(6,24);
puts("记录被删除!!!");
gotoxy(5,25);cputs("按任意键继续");
getch();clrscr();
}
i++;
} /*end search*/
if(found==0)
{
gotoxy(5,14);cputs("无该同学或输入错误,请重新输入...");
cputs("按任意键继续");getch();clrscr();
}
}break;
/*end case '1'*/
case '2':
{found=0,i=0;
gotoxy(1,6);cputs("输入姓名为删除");
gotoxy(23,6); gets(name);
while(found==0&&i<n)
{
if(strcmp(stu[i].name,name)==0)
{
found=1;
gotoxy(5,7); cputs("记录是:");
gotoxy(5,8); puts("姓名 :"); gotoxy(15,8); puts(stu[i].name);
gotoxy(5,9); puts("性别 :"); gotoxy(15,9); puts(stu[i].sex);
gotoxy(5,10); puts("地址 :"); gotoxy(15,10); puts(stu[i].address);
gotoxy(5,11); puts("电话号码:"); gotoxy(15,11); puts(stu[i].tel_num);
gotoxy(5,12); puts("生日 :"); gotoxy(15,12); puts(stu[i].bir_day);
gotoxy(5,13); puts("QQ号码 :"); gotoxy(15,13); puts(stu[i].qq);
gotoxy(5,14); puts("电子邮箱:"); gotoxy(15,14); gets(stu[i].e_mail);
gotoxy(5,16);cputs("确定删除吗?");
rewind(fp); puts("确定删除吗,y/n?");
if(getch()=='y')
{
for(k=0;k<n-1;k++)
{ fwrite(&stu[k],sizeof(struct record),1,fp);
fputs("\n",fp);
}/*end for */
gotoxy(6,24);
puts("记录被删除!!!");
gotoxy(5,25);cputs("按任意键继续");
getch();clrscr();
}
i++;
} /*end search*/
if(found==0)
{
gotoxy(5,14);cputs("无该同学或输入错误,请重新输入...");
cputs("按任意键继续");getch();clrscr();
}
}break;
case'3':
{found=0,i=0;
gotoxy(1,6);cputs("输入e_mail为删除");
gotoxy(23,6); gets(e_mail);
while(found==0&&i<n)
{
if(strcmp(stu[i].e_mail,e_mail)==0)
{
found=1;
gotoxy(5,7); cputs("记录是:");
gotoxy(5,8); puts("姓名 :"); gotoxy(15,8); puts(stu[i].name);
gotoxy(5,9); puts("性别 :"); gotoxy(15,9); puts(stu[i].sex);
gotoxy(5,10); puts("地址 :"); gotoxy(15,10); puts(stu[i].address);
gotoxy(5,11); puts("电话号码:"); gotoxy(15,11); puts(stu[i].tel_num);
gotoxy(5,12); puts("生日 :"); gotoxy(15,12); puts(stu[i].bir_day);
gotoxy(5,13); puts("QQ号码 :"); gotoxy(15,13); puts(stu[i].qq);
gotoxy(5,14); puts("电子邮箱:"); gotoxy(15,14); gets(stu[i].e_mail);
gotoxy(5,16);cputs("确定删除吗?");
rewind(fp); puts("确定删除吗,y/n?");;
if(getch()=='y')
{
for(k=0;k<n-1;k++)
{ fwrite(&stu[k],sizeof(struct record),1,fp);
fputs("\n",fp);
}/*end for */
gotoxy(6,24);
puts("记录被删除!!!");
gotoxy(5,25);cputs("按任意键继续");
getch();clrscr();
}
i++;
} /*end search*/
if(found==0)
{
gotoxy(5,14);cputs("无该同学或输入错误,请重新输入...");
cputs("按任意键继续");getch();clrscr();
}
}break;
case '4':{fclose(fp);exit=1;}break;
default :cputs("输入正确数据!");
}/*End switch*/
}/*end while*/
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -