| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1588 人关注过本帖
标题:[求助]帮改一下
只看楼主 加入收藏
空前
Rank: 1
等 级:新手上路
帖 子:1146
专家分:0
注 册:2004-5-11
收藏
 问题点数:0 回复次数:25 
[求助]帮改一下

写了几天的一个小程序,

好不容打到TC上, 但有一个错误,只有一个错误,

确找不出错在哪,望各位高手给改一下!感激涕零!

为了不让你眼花,我贴到楼下:

2004-09-22 17:39
空前
Rank: 1
等 级:新手上路
帖 子:1146
专家分:0
注 册:2004-5-11
收藏
得分:0 

#include<stdio.h> #include<stdlib.h> #include<string.h> #define M 20 #define L 100 struct aa {char name[M]; char word[M]; }user[L]; int n=0;

int jia() {int a,b; randomize(); a=random(100); randomize(); b=random(100); printf("%d+%d=",a,b); return a+b; }

int jian() {int a,b; while(2) {randomize(); a=random(100); randomize(); b=random(100); if(a>=b) break; } printf("%d-%d=",a,b); return a-b; }

int chen() {int a,b; randomize(); a=random(9)+1; randomize(); b=random(9)+1; printf("%d*%d=",a,b); return a*b; }

int chu() {int a,b,c; while(3) {randomize(); a=random(82); randomize(); b=random(9)+1; if(a>=b) break; } c=a%b;a=a-c; printf("%d/%d=",a,b); return a/b; }

void math() {int a,b,n,i;float s=0,k; printf("How many practise do you want to do?\n"); scanf("%d",&n);k=100.0/n; printf("OK,every practise %.2f'\n\n",k); for(i=1;i<=n;i++) {printf("practise %2d: ",i); randomize(); a=random(4); switch(a) {case 0:b=jia();break; case 1:b=jian();break; case 2:b=chen();break; default:b=chu(); } scanf("%d",&a); if(a==b) {printf("OK,very good!\t +%.2f'\n\n",k); s=s+k;} else printf("Sorry,it's wrong!\n\n"); } printf("\n\nThe totall=%.2f'",s); getch(); }

void getpassword(char p[]) {unsigned i=0,j; while((j=getch())!=13&&i<M-1) {p[i++]=j; printf("*"); } p[i]='\0'; printf("\n"); return; }

void list() {int i,j; clrscr(); printf("\n\n"); for(i=1;i<10;i++) {for(j=1;j<=i;j++) printf("%d*%d=%d\t",j,i,j*i); printf("\n"); } printf("\n\nPress any key to return.\n"); getch(); return; }

int save() {FILE *fp; int i; if((fp=fopen("n_file","wb"))==NULL) {printf("Can not open file.\n"); return 0; } if(fwrite(&n,sizeof(int),1,fp)!=1) {printf("Write error!\n"); return 0; } fclose(fp); if((fp=fopen("u_file","wb"))==NULL) {printf("Can not open file.\n"); return 0; } for(i=0;i<n;i++) if(fwrite(&user[i],sizeof(struct aa),1,fp)!=1) {printf("User write error!\n"); return 0; } fclose(fp); printf("Save successfull!\n"); getch(); return 1; }

int load() {FILE *fp; int i; if((fp=fopen("n_file","rb"))==NULL) {printf("Can not open 'n_file'.\n"); return 0; } if(fread(&n,sizeof(int),1,fp)!=1) {printf("'n_file read error!\n"); return 0; } fclose(fp); if((fp=fopen("u_file","rb"))==NULL) {printf("Can not open 'u_file'.\n"); return 0; } for(i=0;i<n;i++) if(fread(&user[i],sizeof(struct aa),1,fp)!=1) {printf("'u_file' read error!\n"); return 0; } fclose(fp); return 1; }

int quit() { char c; if(save()!=1) {printf("The data not save.\n"); printf("Do you want to quite(y/n)?"); c=getchar(); if(c=='y'||c=='Y') return 0; else return 1; } else return 0; }

int textn(char *p) {int i; for(i=0;i<n;i++) if(strcmp(p,user[i].name)==0) break; if(i>=n) i=-1; return i; }

int textw(char *p,int i) { return strcmp(p,user[i].word)==0?1:0; }

int text(char *p,char *q) {int i,j,k=0; i=textn(p); if(i>=0) {j=textw(q,i); if(j==1) k=1; else printf("The password error!\n"); } else printf("The user name is not zhuce.\n"); return k; }

void zhuce() { char a[M],b[2][M]; int i; clrscr(); printf("\tCreate A New User\n\n"); if(n>=M) {printf("The user is full!\n"); printf("Press any key to return.\n"); getch(); return;} printf("Input username:"); gets(a); printf("Input password:"); getpassword(b[0]); printf("Input password:"); getpassword(b[1]); i=textn(a); if(i>=0) printf("The user name had be used!\n"); else if(strcmp(b[0],b[1])==0) {strcpy(user[n].name,a); srtcpy(user[n].word,b[0]); n++; printf("zhuce sucessfull!\n"); } else printf("The two password is not same.\n"); printf("\n\n\nPress any key to return.\n"); getch(); return; }

void other() {int i,flag=1; clrscr(); while(2) { while(3) {printf("\t\tThe Other\n\n"); printf("1.A usefull list.\n"); printf("2.Some math practice.\n"); printf("3.Exit.\n"); printf("\n\n\nPlease choose(1~3):"); scanf("%d",&i); if(i<1||i>3) {printf("choose error!\n"); printf("Press any key to continue.\n"); getch();} else break; } switch(i) {case 1: list(); break; case 2: math(); break; default:flag=0; } if(flag==0) break; } printf("\n\nPress any to return.\n"); getch(); return; }

void sum(int *p,int k) {int i,s=0; for(i=0;i<k;i++) s+=p[i]; printf("The sum=%d .\n",s); return; }

void sort(int *p,int k) {int t,i,j; for(i=0;i<k-1;i++) for(j=i+1;i<k;j++) if(p[i]>p[j]) {t=p[i]; p[i]=p[j]; p[j]=t;} printf("After sort:\n"); for(i=0;i<k;i++) printf("%6d",p[i]); printf("\n"); return; }

void min(int *p,int k) {int i,t=p[0]; for(i=1;i<k;i++) if(t>p[i]) t=p[i]; printf("The min=%d .\n",t); return; }

void max(int *p,int k) {int i,t=p[0]; for(i=1;i<k;i++) if(t<p[i]) t=p[i]; printf("The max=%d .\n",t); return; }

void everage(int *p,int k) {int i;float k=0; for(i=0;i<k;i++) k+=p[i]; k=k/n; printf("The everage=%.2f .\n",k); return; }

void process() {int a[100],b,i,k,flag=1; while(2) {printf("\n\nHow many numbers do you want to process?\n"); scanf("%d",&b); if(b<=0||b>100) printf("Input error!\n"); else break; } printf("Input the numbers:\n"); for(i=0;i<b;i++) {printf("%2d :",i+1); scanf("%d",&a[i]);} printf("\n\nOK,press any key to continue.\n"); getch(); clrscr(); while(3) {clrscr(); while(3) {printf("\tThe Data Process System\n\n"); printf("0.Exit.\n"); printf("1.Sum.\n"); printf("2.Sort.\n"); printf("3.min.\n"); printf("4.max.\n"); printf("5.everage.\n"); printf("\n\n\nPlease choose(0~5):"); scanf("%d",&k); if(k<0||k>5) {printf("Choose error!\n"); printf("Press any key to continue.\n"); getch();} else break; } switch(k) {case 0: flag=0;break; case 1: sum(a,b);break; case 2: sort(a,b);break; case 3: min(a,b);break; case 4: max(a,b);break; default:everage(a,b); } if(flag==0) break; printf("\n\nPress any key to continue.\n"); getch(); } printf("\nPress any key to return.\n"); getch(); return; }

void password() {int i,j; char a[M],b[M],c[2][M]; clrscr(); printf("\t\tModify Password\n\n"); printf("Input username:"); gets(a); printf("Input password:"); getpassword(b); printf("New password:"); getpassword(c[0]); printf("New password:"); getpassword(c[1]); i=text(a,b); if(i) {if(strcmp(c[0],c[1])==0) {j=textn(a); strcpy(user[j].word,c[0]); printf("\nOK,modify password success!\n"); } else printf("The two password is not same.\n"); } printf("\n\nPress any key to return.\n"); getch(); return; }

void denlu() {char a[M],b[M]; int i,k,flag=1; clrscr(); printf("\t\tDen Lu\n\n"); printf("Input username:"); gets(a); printf("Input password:"); getpassword(b); i=text(a,b); if(i) {printf("Load successfull!\n"); printf("\n\nPress any key to continue.\n"); getch(); clrscr();} while(i) {while(2) {printf("%s : Welcome to use this program.\n\n\n"); printf("1.The data process system.\n"); printf("2.Others.\n"); printf("3.Exit.\n"); printf("\n\nPlease choose(1~3):"); scnaf("%d",&k); if(k<1||k>3) {printf("Choose error!\n"); printf("Press any key to continue.\n"); getch();} else break; } switch(k) {case 1: process();break; case 2: Other(); break; default: flag=0; } if(flag==0) break; } printf("Press any key to return.\n"); getch(); return; }

void main() {int i,flag=1; load(); while(1) {clrscr(); while(2) {printf("\t\tA Small Program\n\n"); printf("1.Create a new user.\n"); printf("2.Denlu.\n"); printf("3.Modify password.\n"); printf("4.Close this program.\n"); printf("\n\nPlease choose(1~4):"); scanf("%d",&i); if(i>4||i<1) {printf("Choose error!\n"); printf("Press any key to continue.\n"); getch();} else break; } switch(i) {case 1:zhude();break; case 2:denlu();break; case 3:password();break; default:flag=quit(); } if(flag==0) break; } printf("Thanks for your using!\n"); printf("\nPress any key to close.\n"); getch(); printf("You can close this window.\n"); }

就这么多


2004-09-22 17:40
空前
Rank: 1
等 级:新手上路
帖 子:1146
专家分:0
注 册:2004-5-11
收藏
得分:0 

TC 上面提示只有一个错误,但不知道错在哪?

望大哥们帮调试一下,谢谢了!


2004-09-22 17:41
天使预备役
Rank: 2
等 级:论坛游民
威 望:3
帖 子:670
专家分:10
注 册:2004-4-6
收藏
得分:0 

什么错误,把错误显示发看一下!!!


差点把你忘了...
2004-09-22 18:54
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
收藏
得分:0 

帮你调通了,程序我没有看,逻辑问题自己改。

1。自定义函数不能用与库函数重名的

2。大小写对C来说是两个不同的名

3。库函数名写错

4。是不是还有4我也忘记了

#include<stdio.h> #include<stdlib.h> #include<string.h> #define M 20 #define L 100 struct aa { char name[M]; char word[M]; } user[L]; int n=0 ;

int jia() { int a,b ; randomize(); a=random(100); randomize(); b=random(100); printf("%d+%d=",a,b); return a+b ; }

int jian() { int a,b ; while(2) { randomize(); a=random(100); randomize(); b=random(100); if(a>=b)break ; } printf("%d-%d=",a,b); return a-b ; }

int chen() { int a,b ; randomize(); a=random(9)+1 ; randomize(); b=random(9)+1 ; printf("%d*%d=",a,b); return a*b ; }

int chu() { int a,b,c ; while(3) { randomize(); a=random(82); randomize(); b=random(9)+1 ; if(a>=b)break ; } c=a%b ; a=a-c ; printf("%d/%d=",a,b); return a/b ; }

void math() { int a,b,n,i ; float s=0,k ; printf("How many practise do you want to do?\n"); scanf("%d",&n); k=100.0/n ; printf("OK,every practise %.2f'\n\n",k); for(i=1;i<=n;i++) { printf("practise %2d: ",i); randomize(); a=random(4); switch(a) { case 0 :b=jia();break ; case 1 :b=jian();break ; case 2 :b=chen();break ; default :b=chu(); } scanf("%d",&a); if(a==b) { printf("OK,very good!\t +%.2f'\n\n",k); s=s+k ; } else printf("Sorry,it's wrong!\n\n"); } printf("\n\nThe totall=%.2f'",s); getch(); }

void getpassword(char p[]) { unsigned i=0,j ; while((j=getch())!=13&&i<M-1) { p[i++]=j ; printf("*"); } p[i]='\0' ; printf("\n"); return ; }

void list() { int i,j ; clrscr(); printf("\n\n"); for(i=1;i<10;i++) { for(j=1;j<=i;j++) printf("%d*%d=%d\t",j,i,j*i); printf("\n"); } printf("\n\nPress any key to return.\n"); getch(); return ; }

int save() { FILE*fp ; int i ; if((fp=fopen("n_file","wb"))==NULL) { printf("Can not open file.\n"); return 0 ; } if(fwrite(&n,sizeof(int),1,fp)!=1) { printf("Write error!\n"); return 0 ; } fclose(fp); if((fp=fopen("u_file","wb"))==NULL) { printf("Can not open file.\n"); return 0 ; } for(i=0;i<n;i++) if(fwrite(&user[i],sizeof(struct aa),1,fp)!=1) { printf("User write error!\n"); return 0 ; } fclose(fp); printf("Save successfull!\n"); getch(); return 1 ; }

int load() { FILE*fp ; int i ; if((fp=fopen("n_file","rb"))==NULL) { printf("Can not open 'n_file'.\n"); return 0 ; } if(fread(&n,sizeof(int),1,fp)!=1) { printf("'n_file read error!\n"); return 0 ; } fclose(fp); if((fp=fopen("u_file","rb"))==NULL) { printf("Can not open 'u_file'.\n"); return 0 ; } for(i=0;i<n;i++) if(fread(&user[i],sizeof(struct aa),1,fp)!=1) { printf("'u_file' read error!\n"); return 0 ; } fclose(fp); return 1 ; }

int quit() { char c ; if(save()!=1) { printf("The data not save.\n"); printf("Do you want to quite(y/n)?"); c=getchar(); if(c=='y'||c=='Y')return 0 ; else return 1 ; } else return 0 ; }

int textn(char*p) { int i ; for(i=0;i<n;i++) if(strcmp(p,user[i].name)==0)break ; if(i>=n)i=-1 ; return i ; }

int textw(char*p,int i) { return strcmp(p,user[i].word)==0?1:0 ; }

int text(char*p,char*q) { int i,j,k=0 ; i=textn(p); if(i>=0) { j=textw(q,i); if(j==1)k=1 ; else printf("The password error!\n"); } else printf("The user name is not zhuce.\n"); return k ; }

void zhuce() { char a[M],b[2][M]; int i ; clrscr(); printf("\tCreate A New User\n\n"); if(n>=M) { printf("The user is full!\n"); printf("Press any key to return.\n"); getch(); return ; } printf("Input username:"); gets(a); printf("Input password:"); getpassword(b[0]); printf("Input password:"); getpassword(b[1]); i=textn(a); if(i>=0)printf("The user name had be used!\n"); else if(strcmp(b[0],b[1])==0) { strcpy(user[n].name,a); strcpy(user[n].word,b[0]); n++; printf("zhuce sucessfull!\n"); } else printf("The two password is not same.\n"); printf("\n\n\nPress any key to return.\n"); getch(); return ; }

void other1() { int i,flag=1 ; clrscr(); while(2) { while(3) { printf("\t\tThe Other\n\n"); printf("1.A usefull list.\n"); printf("2.Some math practice.\n"); printf("3.Exit.\n"); printf("\n\n\nPlease choose(1~3):"); scanf("%d",&i); if(i<1||i>3) { printf("choose error!\n"); printf("Press any key to continue.\n"); getch(); } else break ; } switch(i) { case 1 : list(); break ; case 2 : math(); break ; default : flag=0 ; } if(flag==0)break ; } printf("\n\nPress any to return.\n"); getch(); return ; }

void sum(int*p,int k) { int i,s=0 ; for(i=0;i<k;i++) s+=p[i]; printf("The sum=%d .\n",s); return ; }

void sort(int*p,int k) { int t,i,j ; for(i=0;i<k-1;i++) for(j=i+1;i<k;j++) if(p[i]>p[j]) { t=p[i]; p[i]=p[j]; p[j]=t ; } printf("After sort:\n"); for(i=0;i<k;i++) printf("%6d",p[i]); printf("\n"); return ; }

void min1(int*p,int k) { int i,t=p[0];

for(i=1;i<k;i++) if(t>p[i])t=p[i]; printf("The min=%d .\n",t); return ; }

void max1(int*p,int k) { int i,t=p[0]; for(i=1;i<k;i++) if(t<p[i])t=p[i]; printf("The max=%d .\n",t); return ; }

void everage(int*p,int k1) { int i ; float k=0 ; for(i=0;i<k1;i++) k+=p[i]; k=k/n ; printf("The everage=%.2f .\n",k); return ; }

void process() { int a[100],b,i,k,flag=1 ; while(2) { printf("\n\nHow many numbers do you want to process?\n"); scanf("%d",&b); if(b<=0||b>100)printf("Input error!\n"); else break ; } printf("Input the numbers:\n"); for(i=0;i<b;i++) { printf("%2d :",i+1); scanf("%d",&a[i]); } printf("\n\nOK,press any key to continue.\n"); getch(); clrscr(); while(3) { clrscr(); while(3) { printf("\tThe Data Process System\n\n"); printf("0.Exit.\n"); printf("1.Sum.\n"); printf("2.Sort.\n"); printf("3.min.\n"); printf("4.max.\n"); printf("5.everage.\n"); printf("\n\n\nPlease choose(0~5):"); scanf("%d",&k); if(k<0||k>5) { printf("Choose error!\n"); printf("Press any key to continue.\n"); getch(); } else break ; } switch(k) { case 0 : flag=0 ; break ; case 1 : sum(a,b); break ; case 2 : sort(a,b); break ; case 3 : min1(a,b); break ; case 4 : max1(a,b); break ; default : everage(a,b); } if(flag==0)break ; printf("\n\nPress any key to continue.\n"); getch(); } printf("\nPress any key to return.\n"); getch(); return ; }

void password() { int i,j ; char a[M],b[M],c[2][M]; clrscr(); printf("\t\tModify Password\n\n"); printf("Input username:"); gets(a); printf("Input password:"); getpassword(b); printf("New password:"); getpassword(c[0]); printf("New password:"); getpassword(c[1]); i=text(a,b); if(i) { if(strcmp(c[0],c[1])==0) { j=textn(a); strcpy(user[j].word,c[0]); printf("\nOK,modify password success!\n"); } else printf("The two password is not same.\n"); } printf("\n\nPress any key to return.\n"); getch(); return ; }

void denlu() { char a[M],b[M]; int i,k,flag=1 ; clrscr(); printf("\t\tDen Lu\n\n"); printf("Input username:"); gets(a); printf("Input password:"); getpassword(b); i=text(a,b); if(i) { printf("Load successfull!\n"); printf("\n\nPress any key to continue.\n"); getch(); clrscr(); } while(i) { while(2) { printf("%s : Welcome to use this program.\n\n\n"); printf("1.The data process system.\n"); printf("2.Others.\n"); printf("3.Exit.\n"); printf("\n\nPlease choose(1~3):"); scanf("%d",&k); if(k<1||k>3) { printf("Choose error!\n"); printf("Press any key to continue.\n"); getch(); } else break ; } switch(k) { case 1 : process(); break ; case 2 : other1(); break ; default : flag=0 ; } if(flag==0)break ; } printf("Press any key to return.\n"); getch(); return ; }

void main() { int i,flag=1 ; load(); while(1) { clrscr(); while(2) { printf("\t\tA Small Program\n\n"); printf("1.Create a new user.\n"); printf("2.Denlu.\n"); printf("3.Modify password.\n"); printf("4.Close this program.\n"); printf("\n\nPlease choose(1~4):"); scanf("%d",&i); if(i>4||i<1) { printf("Choose error!\n"); printf("Press any key to continue.\n"); getch(); } else break ; } switch(i) { case 1 : zhuce(); break ; case 2 : denlu(); break ; case 3 : password(); break ; default : flag=quit(); } if(flag==0)break ; } printf("Thanks for your using!\n"); printf("\nPress any key to close.\n"); getch(); printf("You can close this window.\n"); }


九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2004-09-22 19:50
空前
Rank: 1
等 级:新手上路
帖 子:1146
专家分:0
注 册:2004-5-11
收藏
得分:0 
错误是:声明语法错误,不知道怎么改!

2004-09-23 00:14
空前
Rank: 1
等 级:新手上路
帖 子:1146
专家分:0
注 册:2004-5-11
收藏
得分:0 

帮你调通了,程序我没有看,逻辑问题自己改。

1。自定义函数不能用与库函数重名的

2。大小写对C来说是两个不同的名

3。库函数名写错

4。是不是还有4我也忘记了

请问一下哪个函数与库函数同名啊?


2004-09-23 03:59
空前
Rank: 1
等 级:新手上路
帖 子:1146
专家分:0
注 册:2004-5-11
收藏
得分:0 

看出来了,是min 和 max ,非常感谢!

他们是库函数吗,在哪个文件头中?

函数原型能写出来吗?


2004-09-23 04:00
空前
Rank: 1
等 级:新手上路
帖 子:1146
专家分:0
注 册:2004-5-11
收藏
得分:0 

还有other这个库函数吗?

望给出函数原型,和所在的文件头.


2004-09-23 04:04
空前
Rank: 1
等 级:新手上路
帖 子:1146
专家分:0
注 册:2004-5-11
收藏
得分:0 

你说我的库函数写错了,我看不出来,不知道是哪错了.

望指出!


2004-09-23 04:05
快速回复:[求助]帮改一下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.056819 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved