| 网站首页 | 业界新闻 | 群组 | 人才 | 技术文章 | 下载频道 | 博客 | 代码贴 | 编程论坛
共有 126 人关注过本帖
标题:c语音代码错误问题求教各位大神!
只看楼主 收藏
moonseawind
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2017-11-15
结帖率:0
  已结贴   问题点数:20  回复次数:4   
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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;roomno&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bedno&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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&nbsp;&nbsp;&nbsp;name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;roomno&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bedno&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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&nbsp;&nbsp;&nbsp; name&nbsp;&nbsp;&nbsp; roomno&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bedno&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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&nbsp;&nbsp;&nbsp; name&nbsp;&nbsp;&nbsp; roomno&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bedno&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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;
}

}
附件: 您没有浏览附件的权限,请 登录注册
2017-11-15 15:22
moonseawind
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2017-11-15
  得分:0 
没人吗?....
2017-11-15 15:37
炎天
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:桃花岛
等 级:版主
威 望:24
帖 子:1142
专家分:4351
注 册:2016-9-15
  得分:7 
以下是引用moonseawind在2017-11-15 15:37:26的发言:

没人吗?....

人是应该有的!
这么长,大家有那么多时间么!
你要干什么都不说出来, 你自己认为主要出错的地方在哪呢?
警告和错误信息都给出了,

一万年太久,只争朝夕
2017-11-15 15:54
grmmylbs
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:45
帖 子:1213
专家分:5076
注 册:2016-2-14
  得分:7 
错误太多了,完全没基础

#define m 50
typedef  struct

后面address都是大写;
还有结构体数组应该不能这样赋值吧t[j - 1] = t[j];
2017-11-15 16:29
吹水佬
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:117
帖 子:4657
专家分:18890
注 册:2014-5-20
  得分:7 
那么多错?
重写吧,边写边调试,出一个错就解决一个。
2017-11-15 16:32







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

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