|
主题: 帮我查错~~
|
 5D非线性编辑版主
职务:版主
等级:7
金币:29.0
发贴:6498
注册:2002/3/24 5:05:35
|
#12002/7/7 20:20:27
#include #include #include struct data {char name[20];char sex[5];char Email[20];char address[20]; int age;long int Tel;long int OICQ; }data[10]; FILE *fp; struct data *p; 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; p=data; 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); } puts(" If you don`t want to input info, press 'ENTER'\n"); puts(" Please input the linkman`s name:\n"); scanf("%c",p->name); while(p->name!='\0') {puts("Please input the linkman`s sex:\n"); scanf("%c",p->sex); puts("Please input the linkman`s Email:\n"); scanf("%lu",p->Email); puts("Please input the linkman`s Age:\n"); scanf("%d",&p->age); puts("Please input the linkman`s Tel number:\n"); scanf("%d",&p->Tel); puts("Please input the linkman`s OICQ number:\n"); scanf("%d",&p->OICQ); puts("Please input the linkman`s address:\n"); scanf("%d",p->address); fwrite(p,sizeof(struct data),1,fp); if(fwrite(p,sizeof(struct data),1,fp)!=1) puts("File write error!Please input again\n"); p++; } fclose(fp); }
data_find() {char c2; 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); }
}
data_crt() {p=data; puts(" If you don`t want to input info, press 'ENTER'\n"); puts(" Please input the linkman`s name:\n"); scanf("%c",p->name); while(p->name!='\0') {puts("Please input the linkman`s sex:\n"); scanf("%c",p->sex); puts("Please input the linkman`s Email:\n"); scanf("%lu",p->Email); puts("Please input the linkman`s Age:\n"); scanf("%d",&p->age); puts("Please input the linkman`s Tel number:\n"); scanf("%d",&p->Tel); puts("Please input the linkman`s OICQ number:\n"); scanf("%d",&p->OICQ); puts("Please input the linkman`s address:\n"); scanf("%d",p->address); fwrite(p,sizeof(struct data),1,fp); if(fwrite(p,sizeof(struct data),1,fp)!=1) puts("File write error!Please input again\n"); p++; } fclose(fp);
答对有奖励呦~~
编辑历史:[这消息被天堂鬼火编辑过(编辑时间2002-07-07 21:15:30)] [这消息被天堂鬼火编辑过(编辑时间2002-07-08 14:25:37)]
|
 5D公害
职务:普通成员
等级:9
金币:10.3
发贴:36272
注册:2002/1/13 9:52:57
|
#22002/7/7 21:36:46
哭,从来没学过C。。。。。。。。。
|
 5D限制级
职务:普通成员
等级:6
金币:10.0
发贴:4970
注册:2001/8/16 14:52:34
|
#32002/7/7 22:07:22
讨厌编程 刚开始觉得好玩 学着学着就失去信心了
|
 5D非线性编辑版主
职务:版主
等级:7
金币:29.0
发贴:6498
注册:2002/3/24 5:05:35
|
#42002/7/8 2:47:04
我给他100分,谁改???  机不可失呀~~ 100分
|
 Pretender
职务:普通成员
等级:2
金币:10.0
发贴:510
注册:2001/5/11 21:19:46
|
#52002/7/8 9:17:46
有错吗?给个提示,我正在学PASCAL,帮你看看
|
 5D公害
职务:普通成员
等级:9
金币:10.3
发贴:36272
注册:2002/1/13 9:52:57
|
#62002/7/8 10:12:50
我打小报告去看能加多少分~
|
 绿茶
职务:普通成员
等级:8
金币:10.0
发贴:19267
注册:2000/12/28 12:10:01
|
#72002/7/8 10:44:43
出错提示在哪呀? 否则看起来很麻烦的
|
 5D非线性编辑版主
职务:版主
等级:7
金币:29.0
发贴:6498
注册:2002/3/24 5:05:35
|
#82002/7/8 14:24:19
程序本身没有语法错误, 就是 data_crt()中, 所有的scanf都不能用! 不知道为什么?  是指针P的因素吗?
编辑历史:[这消息被天堂鬼火编辑过(编辑时间2002-07-08 14:27:29)]
|
 绿茶
职务:普通成员
等级:8
金币:10.0
发贴:19267
注册:2000/12/28 12:10:01
|
#92002/7/8 14:29:39
看你有些加&,有些不加&,应该是指针的原因
|
 5D非线性编辑版主
职务:版主
等级:7
金币:29.0
发贴:6498
注册:2002/3/24 5:05:35
|
#102002/7/8 14:45:29
三色,你会不会C语言~~ 肯定要有的地方加,因为那是数据不是地址! 再来看看,怎么办呀???
|
 酷儿MM
职务:普通成员
等级:1
金币:0.0
发贴:176
注册:2002/6/27 20:58:00
|
#112002/7/8 14:56:05
偶也没看出那有错啊,不过可能我只是会简单的啦。。。几年前在学校的水平啦!
|
 5D非线性编辑版主
职务:版主
等级:7
金币:29.0
发贴:6498
注册:2002/3/24 5:05:35
|
#122002/7/8 21:31:43
最终版,绝对没有语法错误! 但测试不通过~~  #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);} } }
|
 x_wolf
职务:普通成员
等级:1
金币:18.0
发贴:4242
注册:2004/8/1 16:08:24
|
#132002/7/8 21:37:06
你先禁用笑脸转换!看不清!
|
 未入流
职务:普通成员
等级:1
金币:0.0
发贴:165
注册:2002/7/5 21:46:46
|
|
 5D非线性编辑版主
职务:版主
等级:7
金币:29.0
发贴:6498
注册:2002/3/24 5:05:35
|
|