 5D非线性编辑版主
职务:版主
等级:7
金币:29.0
发贴:6498
注册:2002/3/24 5:05:35
|
#162002/7/8 22:13:19
#include #include #include #define format "%s%s%d%ld%ld%lu%s" struct data {char name[20];char sex[10];char Email[20];char address[30]; int age;long int Tel;long int OICQ; }data[100]; FILE *fp; int i=0; main()
{char c; clrscr(); window(1, 1, 80, 25); textbackground(7); textcolor(10); gotoxy(15,10); puts("welcome to address book searching system\n"); puts(" If you want to add new data please select 'a'\n"); puts(" if you want to search info please select 'f'\n");
again: c=getchar(); getchar(); if(c=='a'||c=='A') data_add(); else if(c=='f'||c=='F') data_find();
else {gotoxy(15,16); cputs("Error,you select wrong!\n"); cputs("Please select again!\n"); goto again;} }
data_add() {char c1,c3; if((fp=fopen("data.txt","r"))==NULL) {puts("Sorry there isn`t any data,do you want to create onr?(Y/N)\n"); c1=getchar(); getchar(); if(c1=='y'||c1=='Y') data_crt(); else exit(0); } create: puts(" Please input the linkman`s name:\n"); scanf("%s",data[i].name); puts("Please input the linkman`s sex:\n"); scanf("%s",data[i].sex); puts("Please input the linkman`s Email:\n"); scanf("%lu",data[i].Email); puts("Please input the linkman`s Age:\n"); scanf("%d",&data[i].age); puts("Please input the linkman`s Tel number:\n"); scanf("%ld",&data[i].Tel); puts("Please input the linkman`s OICQ number:\n"); scanf("%ld",&data[i].OICQ); puts("Please input the linkman`s address:\n"); scanf("%s",data[i].address); fwrite(data,sizeof(struct data),1,fp); if(fwrite(data,sizeof(struct data),1,fp)!=1) puts("File write error!Please input again\n"); i++; puts("you have input a linkman`s info,do you want to input another one?(Y/N)!\n"); c3=getchar(); getchar(); if(c3=='Y'||c3=='y')goto create; else exit(0); fclose(fp);
}
data_find() {char c2,c3,c4; if((fp=fopen("data.txt","r"))==NULL) {puts("Sorry there isn`t any data,do you want to create onr?(Y/N)\n"); c2=getchar(); getchar(); if(c2=='y'||c2=='Y')data_crt(); else exit(0); } find: puts("please select your way to find info\n"); puts("press '1' to find info by name\n"); puts("press '2' to find info by sex\n"); puts("press '3' to find info by age\n"); puts("press '4' to find info by Tel number\n"); puts("press '5' to find info by OICQ\n"); puts("press '6' to find info by address\n"); c3=getchar(); getchar(); switch(c3) { case '1' ata_find1(); case '2' ata_find2(); case '3' ata_find3(); case '4' ata_find4(); case '5' ata_find5(); case '6' ata_find6(); default : {puts("Sorry you select wrong,would you select again?(Y/N)"); c4=getchar(); getchar(); if(c4=='Y'||c4=='y')goto find; else exit(0);} } }
data_crt() {char c5; create: puts(" Please input the linkman`s name:\n"); scanf("%s",data[i].name); puts("Please input the linkman`s sex:\n"); scanf("%s",data[i].sex); puts("Please input the linkman`s Email:\n"); scanf("%lu",data[i].Email); puts("Please input the linkman`s Age:\n"); scanf("%d",&data[i].age); puts("Please input the linkman`s Tel number:\n"); scanf("%ld",&data[i].Tel); puts("Please input the linkman`s OICQ number:\n"); scanf("%ld",&data[i].OICQ); puts("Please input the linkman`s address:\n"); scanf("%s",data[i].address); fwrite(data,sizeof(struct data),1,fp); if(fwrite(data,sizeof(struct data),1,fp)!=1) puts("File write error!Please input again\n"); i++; puts("you have input a linkman`s info,do you want to input another one?(Y/N)!\n"); c5=getchar(); getchar(); if(c5=='Y'||c5=='y')goto create; else exit(0); fclose(fp); }
data_find1() {char c6; char name[20]; puts("Please input the linkman`s name:\n"); gets(name); fread(data,sizeof(struct data),1,fp); for(i=0;i<100;i++) {if(strcmp(name,data[i].name)==0) printf(format,data[i].name,data[i].sex,data[i].age,data[i].Tel,data[i].OICQ,data[i].Email,data[i].address); if(i==100) {puts("Sorry the linkman you find doesn`t exist,do you want create a new info for him?(Y/N)"); c6=getchar(); getchar(); if(c6=='Y'||c6=='y')data_crt(); else exit(0); fclose(fp);} } }
data_find2() {char sex[10];char c7; puts("Please input the linkman`s sex:\n"); gets(sex); fread(data,sizeof(struct data),1,fp); for(i=0;i<100;i++) {if(strcmp(sex,data[i].sex)==0) printf(format,data[i].name,data[i].sex,data[i].age,data[i].Tel,data[i].OICQ,data[i].Email,data[i].address); if(i==100) {puts("Sorry the linkman you find doesn`t exist,do you want create a new info for him?(Y/N)"); c7=getchar(); getchar(); if(c7=='Y'||c7=='y')data_crt(); else exit(0); fclose(fp);} } }
data_find3() {int n1;char c8; puts("Please input the linkman`s age:\n"); scanf("%D",&n1); fread(data,sizeof(struct data),1,fp); for(i=0;i<100;i++) {if(n1==data[i].age) printf(format,data[i].name,data[i].sex,data[i].age,data[i].Tel,data[i].OICQ,data[i].Email,data[i].address); if(i==100) {puts("Sorry the linkman you find doesn`t exist,do you want create a new info for him?(Y/N)"); c8=getchar(); getchar(); if(c8=='Y'||c8=='y')data_crt(); else exit(0); fclose(fp);} } }
data_find4() {long int n2;char c9; puts("Please input the linkman`s Tel:\n"); scanf("%lD",&n2); fread(data,sizeof(struct data),1,fp); for(i=0;i<100;i++) {if(n2==data[i].Tel) printf(format,data[i].name,data[i].sex,data[i].age,data[i].Tel,data[i].OICQ,data[i].Email,data[i].address); if(i==100) {puts("Sorry the linkman you find doesn`t exist,do you want create a new info for him?(Y/N)"); c9=getchar(); getchar(); if(c9=='Y'||c9=='y')data_crt(); else exit(0); fclose(fp);} } }
data_find5() {long int n3;char c10; puts("Please input the linkman`s OICQ:\n"); scanf("%lD",&n3); fread(data,sizeof(struct data),1,fp); for(i=0;i<100;i++) {if(n3==data[i].OICQ) printf(format,data[i].name,data[i].sex,data[i].age,data[i].Tel,data[i].OICQ,data[i].Email,data[i].address); if(i==100) {puts("Sorry the linkman you find doesn`t exist,do you want create a new info for him?(Y/N)"); c10=getchar(); getchar(); if(c10=='Y'||c10=='y')data_crt(); else exit(0); fclose(fp);} } }
data_find6() {char c11;char address[30]; puts("Please input the linkman`s address:\n"); gets(address); fread(data,sizeof(struct data),1,fp); for(i=0;i<100;i++) {if(strcmp(address,data[i].address)==0) printf(format,data[i].name,data[i].sex,data[i].age,data[i].Tel,data[i].OICQ,data[i].Email,data[i].address); if(i==100) {puts("Sorry the linkman you find doesn`t exist,do you want create a new info for him?(Y/N)"); c11=getchar(); getchar(); if(c11=='Y'||c11=='y')data_crt(); else exit(0); fclose(fp);} } }
再发一次~~~~
编辑历史:[这消息被天堂鬼火编辑过(编辑时间2002-07-08 22:14:49)]
|