帮忙看一下,这个程序错在那里,为什么错了
程序代码:
#include <stdio.h> #include <malloc.h> typedef struct Node { int date; struct Node * pNext; } NODE, * PNODE; typedef struct Stack { PNODE pTop; PNODE pBottom; } * PSTACK, STACK; void init(PSTACK); void push(PSTACK, int); void traverse(PSTACK) int main(void) { STACK S; init(&S); //栈初始化 push(&S, 2); // 压栈 traverse(&S); //遍历 return 0; } //栈初始化 void init(PSTACK pS) { PNODE p = (PNODE)malloc(sizeof(NODE)); pS->pBottom = pS->pTop; pS->pBottom->pNext = NULL; return; } //压栈 void push(PSTACK pS, int Val) { PNODE p = (PNODE)malloc(sizeof(NODE)); p->pNext = pS->pTop; pS->pTop = p; pS->pTop->date = Val; return; } //遍历 void traverse(PSTACK pS) { PNODE p = pS->pTop; while(NULL != p->pNext ) { printf("%d ", p->date ); p = p->pNext ; } printf("\n"); return; }建立了一个栈,向栈中压入数据,然后遍历输出
调试的时候光标指向 主函数!
————————————————————
:\VC++\zhan.cpp(20) : warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
F:\VC++\zhan.cpp(20) : error C2146: syntax error : missing ';' before identifier 'main'
F:\VC++\zhan.cpp(20) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
[ 本帖最后由 q215236213 于 2012-8-17 22:07 编辑 ]