c语音代码错误问题求教各位大神!
图是错误代码如下 #include"stdio.h"
#define 50
tyepdef struct
{char number[20];
char name[20];
char roomno[4];
char bedno[2];
int monery[10];
}address;
menu_select()
{char s[80]; int c; gotoxy(1,25);
printf("press any key enter menu.....\n"); getch();
clrscr(); gotoxy(1,1);
printf("****************************MENU******************************\n\n");
printf(" 1. Enter record\n");
printf(" 2. List the file\n");
printf(" 3. Delete a record\n");
printf(" 4. add record\n");
printf(" 5. Save the file\n");
printf(" 6. Load the file\n");
printf(" 7. sort the make new file\n");
printf(" 8. Quit\n");
printf("****************************MENU******************************\n");
do { printf("\n Enter you choice(1-8):");
scanf("%s",s); c=atoi(s);
} while(c<1||c>8);
return c;
}
enter(address t[])
{
int i,n;
char *s;
clrscr();
printf("\nplease input num \n");
scanf("%d",&n);
printf("\nplease input record \n");
printf("num name roomno bedno monery \n");
printf("-----------------------------------------------\n");
for(i=0;i<n;i++)
{scanf("%s%s%s%d",t[i].number,t[i].name,t[i].roomno,t[i].bedno,t[i].monery);
printf("-----------------------------------------------\n");
return n;
}
}
void list(ADDRESS t[],int n)
{
int i;
clrscr();
printf("\n\n**************************************\n");
printf("num name roomno bedno monery \n");
printf("----------------------------------------------\n");
for(i=0;i<n;i++)
{printf("%-20s%-30s%-10s%-2s%-20d\n",t[i].num,t[i].name,t[i].roomno,t[i].bedno,t[i].monery);
if((i+1)%10==0)
{
printf("press any key continue...\n");
getch();
}}
printf("***********************end*****************\n");
}
void print(ADDRESS temp)
{
clrscr();
printf("\n\n**************************************\n");
printf("num name roomno bedno monery\n");
printf("----------------------------------------------\n");
printf("%-20s%-30s%-10s%-2s%-20d\n",t[i].num,t[i].name,t[i].roomno,t[i].bedno,t[i].monery);
printf("***********************end**********************\n");
}
add(ADDRESS t[],int n)
{
ADDRESS temp;
int i,j;
char s[20];
printf("plese input record\n");
printf("*******************************************\n");
printf("num name roomno bedno monery\n");
printf("-------------------------------------------\n");
scanf("%s%s%s%s%d",temp.num,temp.name,temp.roomno,temp.bedno,temp.monery);
printf("----------------------------------------------\n");
printf("plese input locate num\n");
scanf("%s",s);
i=find(t,n,s);
for(j=n-1;j>=i;j--)
{
t[j+i]=t[j],t[j+i]=t[j],t[j+i]=t[j];
}
t[i]=temp,t[i]=temp,t[i]=temp;
n++;
return n;
}
find(ADDRESS t[],int n,char *s)
{
int i;
for(i=0;i<n;i++)
if(strcmp(s,t[i].name)==0)
return i;
return i;
}
delete(ADDRESS t[],int n)
{
char s[20];
int ch=0;
int i,j;
printf("please deleted num\n");
scanf("%s",s);
i=find(t,n,s);
if(i>n-1)
printf("no found not deleted\n");
else
{print(t[i]);
printf("Are you sure delete it(1/0)\n");
scanf("%d",&ch);
if(ch==1)
{
for(j=i+1;j<n;j++)
t[j-1]=t[j];
n--;
}
}
return n;
}
void save(ADDRESS t[],int n)
{
int i;
FILE *fp;
if((fp=fopen("record.txt","wb"))==NULL)
printf("can not open file\n");
else
{
printf("\nSaving file\n");
fprintf(fp,"%d\r\n",n);
for(i=0;i<n;i++)
fprintf(fp,"%s%s%s%s%d",temp.num,temp.name,temp.roomno,temp.bedno,temp.monery);
}
fclose(fp);
printf("****save success***\n");
}
load(ADDRESS t[])
{
int i,n;
FILE *fp;
if((fp=fopen("record.txt","rb"))==0)
printf("can not open file\n");
else
{fscanf(fp,"%d",&n);
for(i=0;i<n;i++)
fscanf(fp,"%s%s%s%s%d",temp.num,temp.name,temp.roomno,temp.bedno,temp.monery);
}
fclose(fp);
printf("You have success read data from file!!!\n");
return n;
}
void sort(ADDRESS t[],int n)
{
int i,j,flag;
ADDRESS temp;
for(i=0;i<n;i++)
{
flag=0;
for(j=0;j<n-1;j++)
if((strcmp(t[j].num,t[j+1].num))>0)
{
flag=1;
temp=t[j],t[j]=t[j+1],t[j+1]=temp;
}
if(flag==0)break;
}
printf("sort sucess!!!\n");
}
main()
{
address adr[m];
int length;
clrscr();
for(;i;)
switch(menu_select())
{ case 1:length=enter(adr);break;
case 2:list(adr,length);break;
case 3:length=delete(adr,length);break;
case 4:length=add(adr,length);break;
case 5:save(adr,length);break;
case 6:length=load(adr);break;
case 7:sort(adr,length);break;
case 8:i=0;
}
}