【发布时间】:2021-10-01 13:33:42
【问题描述】:
我决定使用 C 创建一个堆栈。我刚刚为 push 函数编写了代码,现在我遇到了错误(它说我的 maxsize 有问题)。
如果你问我,一切似乎都刚刚好,我不知道错误可能是什么。
#include <stdio.h>
#include <stdlib.h>
#define maxsize 100;
int top=-1, item;
int s[maxsize];
void push()
{
if (top == maxsize-1)
{
printf("Stack overflow\n");
return;
}
top = top + 1;
s[top] = item;
}
我得到的错误是:-
stack.c:3:20: error: expected ']' before ';' token
#define maxsize 100;
^
stack.c:5:7: note: in expansion of macro 'maxsize'
int s[maxsize];
^~~~~~~
stack.c: In function 'push':
stack.c:3:20: error: expected ')' before ';' token
#define maxsize 100;
^
stack.c:9:16: note: in expansion of macro 'maxsize'
if (top == maxsize-1)
^~~~~~~
stack.c:9:8: note: to match this '('
if (top == maxsize-1)
^
stack.c:16:5: error: 's' undeclared (first use in this function)
s[top]=item;
^
stack.c:16:5: note: each undeclared identifier is reported only once
for each function it appears in
【问题讨论】:
-
能否请您发布错误输出?
标签: c data-structures stack