★【急】Too many types in declaration ???

chunhong89 2010-10-24 09:38:17
★Too many types in declaration 说明中类型太多????
一下代码段出现了这个错误? 为什么啊? 求解释~~~~
需要把完整代码贴出来么?要的话我回帖跟上~~~
速度回,在线等!!!!!!!!!!!!!!!!!!!!!!!!!!!


int IsStackEmpty(Sgoods *S)
{
return(S->top==-1? 1:0);
}

int IsStackFull(Sgoods *S)
{
return(S->top==MAXSIZE-1? 1:0);
}

...全文
204 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
Thirty 2010-10-24
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 bitxinhai 的回复:]
int IsStackEmpty(Sgoods *S)
{
return(S->top==-1? 1:0);
}

你这个函数返回的是int,
while (!IsStackEmpty(S))
这句肯定错误,因为!只能判断bool类型的
[/Quote]!p只用于bool没错,但是用在int上结果没影响,只是那样用不好
bitxinhai 2010-10-24
  • 打赏
  • 举报
回复
int IsStackEmpty(Sgoods *S)
{
return(S->top==-1? 1:0);
}

你这个函数返回的是int,
while (!IsStackEmpty(S))
这句肯定错误,因为!只能判断bool类型的

chunhong89 2010-10-24
  • 打赏
  • 举报
回复
原来是前面没分号~~
chunhong89 2010-10-24
  • 打赏
  • 举报
回复
顺便问问:

while (!IsStackEmpty(S))
{
PopStack(S,&x);
PushStack(B,x) ;
}



出现语法错误. 是什么?
chunhong89 2010-10-24
  • 打赏
  • 举报
回复
@.@!! 怎么回事?! 怎么多了个VOID在前面?!
xiaoyuer5222 2010-10-24
  • 打赏
  • 举报
回复
void
int IsQueueFull (Qgoods *Q)
{
return(Q->rear-Q->front==maxsize? 1:0);
}
前面多了void
chunhong89 2010-10-24
  • 打赏
  • 举报
回复
完整代码:
刚写的,还有其他错误,但主要解决我提问那个!谢谢


#include "stdio.h"
#include "malloc.h"
#define maxsize 50
typedef struct
{
long date[maxsize];
int top;
}Sgoods;

typedef struct
{
long date[maxsize];
int rear;
int front;
}Qgoods;

/*****init*******/

void InitStack(Sgoods *S)
{
S->top=-1;
}
void InitQueue(Qgoods *Q)
{
Q->rear=0;
Q->front=0;
}

/***********Stack*********/

int IsStackEmpty(Sgoods *S)
{
return(S->top==-1? 1:0);
}

int IsStackFull(Sgoods *S)
{
return(S->top==maxsize-1? 1:0);
}

int PushStack(Sgoods *S,long x)
{
if(IsStackFull(S))
return 0;
S->top++;
S->date[S->top]=x;
return 1;
}

int PopStack(Sgoods *S, long *x)
{
if(IsStackEmpty(S))
return 0;
*x=S->date[S->top];
S->top--;
return 1;
}

int GetTop (Sgoods *S, long *x)
{
if (S->top == -1)
return 0;
else
{
*x=S->date[S->top];
return 1;
}
}

void
/*************queue*********/

int IsQueueFull (Qgoods *Q)
{
return(Q->rear-Q->front==maxsize? 1:0);
}

int IsQueueEmpty (Qgoods *Q)
{
return(Q->front==Q->rear? 1:0);
}

int EnterQueue(Qgoods *Q,long x)
{
if(IsQueueFull(Q))
return 0;
Q->date[Q->rear]=x;
Q->rear++;
return 1;
}

int DeleteQueue(Qgoods *Q,long *x)
{
if(IsQueueEmpty(Q))
return 0;
*x=Q->date[Q->front];
Q->front++;
return 1;
}

void JinHuo (Qgoods *Q)
{
while (1)
{
long d=0;
int t=0;
printf("please input the date in produced(as:20100925):\n ");
scanf("%ld",&d);
printf("please input the products' quantity:\n");
scanf("%t",&t);
while (t!=0)
{
EnterQueue(Q, d) ;
t--;
}
printf("JinHuo.......OK\n");
printf("Continue to JinHuo?(Y/N)\n");
if (getchar()=='Y');
else return;
}
}

void ShangJia (Sgoods *S ,Qgoods *Q)
{
long x,y,a;
Sgoods *B=(Sgoods *)malloc(sizeof(Sgoods))
while (!IsStackEmpty(S))
{
PopStack(S,&x);
PushStack(B,x) ;
}
while(!IsQueueEmpty(Q) && !IsStackFull(S))
{
DeleteQueue(Q,&y) ;
PushStack(S,y) ;
}
printf ("ShangJia..........OK\n");
}

void ShouHuo (Sgoods *S)
{
int k,temp;
long a[maxsize];
printf("How many goodses will you like to buy?\n");
scanf("%d",&k);
temp=k;
for (;k>0;k--)
PopStack(S,&a[temp-(k-1)]);
printf("You have buy %d goodses\n",k);
}
void menu(char **menu,int n);
void main()
{
Sgoods *S=(Sgoods *)malloc(sizeof(Sgoods));
// Sgoods *B=(Sgoods *)malloc(sizeof(Sgoods));
Qgoods *Q=(Qgoods *)malloc(sizeof(Qgoods));
int choose=1;
// char *k=" ",
char *s="\n *";
char *xs="**********************************";
while(choose)
{
char *menu1[]={"***************MENU",
"1->JinHuo\n",
"2->ShangJia\n ",
"3->ShouHuo\n",
"0->exit\n"};
menu(menu1,4);
scanf("%d",&choose);
switch(choose)
{
case 1: JinHuo(Q); break;
case 2: ShangJia(S,Q); break;
case 3: ShouHuo(S); break;
case 0: break;
}
getchar();
printf("%s%s******%s*",s,xs,xs);
}

}



try325 2010-10-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xiaoyuer5222 的回复:]

贴完整代码
[/Quote]
就这两个函数看不出啥问题来
bitxinhai 2010-10-24
  • 打赏
  • 举报
回复
Sgoods 你定义了吗??
还有Sgoods 你定义的是结构体变量
还是指向结构体的指针啊。。。
xiaoyuer5222 2010-10-24
  • 打赏
  • 举报
回复
贴完整代码

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧