• 全部
  • 问答

请帮忙检查一下,在线等

imsolo 2003-11-03 09:22:11
写了几个栈的基本函数,主函数用于检查这几个函数,输入十进制数输出八进制数。
出错信息:E:\CFile\Stack\stack.c(29) : error C2143: syntax error : missing ')' before ';'
E:\CFile\Stack\stack.c(29) : error C2059: syntax error : ')'
E:\CFile\Stack\stack.c(29) : error C2100: illegal indirection
E:\CFile\Stack\stack.c(30) : warning C4013: 'exit' undefined; assuming extern returning int
E:\CFile\Stack\stack.c(78) : error C2143: syntax error : missing ')' before ';'
E:\CFile\Stack\stack.c(78) : error C2143: syntax error : missing ';' before ')'
E:\CFile\Stack\stack.c(87) : error C2061: syntax error : identifier 'Pop'
E:\CFile\Stack\stack.c(87) : error C2059: syntax error : ';'
E:\CFile\Stack\stack.c(87) : error C2059: syntax error : 'type'
我实在不知错在那里。代码:
#include <stdio.h>
#include <malloc.h>
#include "Common.h"

#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;

typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;

//函数声明
Status InitStack(SqStack *S); //构造一个空栈S
Status DestroyStack(SqStack *S); //销毁栈S,S不存在
Status ClearStack(SqStack *S); //把S置为空栈
Status StackEmpty(const SqStack *S); //若S置为空栈,则返回TRUE,否则返回FALSE
int StackLength(const SqStack *S); //返回S的元素个数,即栈的长度
Status GetTop(SqStack *S, SElemType *e); //若栈不空,则用e返回S的栈顶元素,并返回OK;否则返回ERROR
Status Push(SqStack *S, SElemType e); //插入元素e为新的栈顶元素
Status Pop(SqStack *S, SElemType *e); //若栈不为空,则删除S的栈顶元素,用e返回其值,并返回OK;否则返回ERROR
Status StackTraverse(SqStack *S, Status (*visit)()); //从栈底到栈顶依次对栈中每个元素调用函数visit()。一旦visit()失败,则操作失败

//函数定义
Status InitStack(SqStack *S)
{
S->base = (SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType));
if (!S->base) exit(OVERFLOW);
S->top = S->base;
S->stacksize = STACK_INIT_SIZE;
return OK;
}

Status DestroyStack(SqStack *S)
{
free(S->base); free(S->top);
if (S->base || S->base)
return ERROR;
else
return OK;
}

Status ClearStack(SqStack *S)
{
S->top = S->base;
if (S->top == S->base)
return OK;
else
return ERROR;
}

Status StackEmpty(const SqStack *S)
{
if (S->top == S->base)
return OK;
else
return ERROR;
}

int StackLength(const SqStack *S)
{
return S->stacksize;
}

Status GetTop(SqStack *S, SElemType *e)
{
if (S->top == S->base) return ERROR;
*e = *(S->top-1);
return OK;
}

Status Push(SqStack *S, SElemType e)
{
if (S->top - S->base >= S->stacksize)
{
S->base = (SElemType *)realloc(S->base,(S->stacksize + STACKINCREMENT) * sizeof(SElemType));
if (!S->base) exit(OVERFLOW);
S->top = S->base + S->stacksize;
S->stacksize += STACKINCREMENT;
}
*S->top++ = e;
return OK;
}

Status Pop(SqStack *S, SElemType *e)
{
if (S->top == S->base) return ERROR;
*e = *--S->top;
return OK;
}

Status StackTraverse(SqStack *S, Status (*visit)())
{
return OK;
}


void main(void)
{
SqStack *S;
int N,e;

InitStack(S);
printf("输入十进制数:");
scanf("%d",&N);
while (N)
{
Push(S, N%8);
N = N/8;
}
while (!StackEmpty(S))
{
Pop(S,&e);
printf("%d",e);
}

printf("Hello, world\n");
}
头文件commom.h
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2

typedef int Status;
//typedef int ElemType;
typedef int SElemType;
...全文
12 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
imsolo 2003-11-04
问题已解决,谢谢!
回复
Andy84920 2003-11-03
同意楼上,不知道还有没有问题!
回复
daizh 2003-11-03
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h> //<-------------添加,否则exit调用出错。
#include "Common.h"

#define STACK_INIT_SIZE 100//<-----------------去掉“;”号
#define STACKINCREMENT 10//<------------------去掉“;”号

typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
回复
发帖
C语言
创建于2007-09-28

6.3w+

社区成员

C语言相关问题讨论
申请成为版主
帖子事件
创建了帖子
2003-11-03 09:22
社区公告
暂无公告