C语言菜鸟求助,关于C语言链表的一个问题,显示有四个错误,一个警告,哪里错了啊?怎么改?

#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<math.h>

# define MAXSIZE 100
typedef struct{
int *top; //栈顶指针
int *base; //栈底指针
int stacksize; //栈容量
}SqStack;
void Initstack(); //构造一个空栈

void main(){
SqStack S;
InitStack(S);
system("pause");
}
void InitStack(SqStack &S){ //构造一个空栈
S.base=(int *)malloc(MAXSIZE*sizeof(int));
if(!S.base) exit(0); //存储空间失败
S.top=S.base;
S.stacksize=MAXSIZE;
}

#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<math.h>

# define MAXSIZE 100
typedef struct{
    int *top;        //栈顶指针
    int *base;        //栈底指针
    int stacksize;    //栈容量
}SqStack;
void InitStack( SqStack &S );        //ERROR  一、函数名写错了,二、函数声明与函数定义不符

void main(){
    SqStack S;
    InitStack(S);
    system("pause");
}
void InitStack(SqStack &S){ //构造一个空栈
    S.base=(int *)malloc(MAXSIZE*sizeof(int));
    if(!S.base) exit(0); //存储空间失败
    S.top=S.base;
    S.stacksize=MAXSIZE;
}

追问

可是为什么编译还是出错啊?

追答

提供错误图片,我在VC6通过了的

追问

追答

你把程序名的扩展名改成.cpp
因为.c时,是按c语言进行编译,C语言不支持引用 &这个符号!!
引用是C++引入的新特性!表示使用变量的别名

温馨提示:内容为网友见解,仅供参考
第1个回答  2014-09-13

我检查了下面网友的代码,这应该是没有问题的,问题可能是你的编译器,我给你把这段代码改成用标准c写的,再编译不通过可没办法了。

#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<math.h>

# define MAXSIZE 100
typedef struct{
    int *top;        //栈顶指针
    int *base;        //栈底指针
    int stacksize;    //栈容量
}SqStack;
void InitStack( SqStack *S );

int main(){
    SqStack S;
    InitStack(&S);
    free(S.base);
    system("pause");
}
void InitStack(SqStack *S){ //构造空栈
    S->base=(int *)malloc(MAXSIZE*sizeof(int));
    if(!S->base) exit(0); //存储空间失败
    S->top=S->base;
    S->stacksize=MAXSIZE;
}

追问

问题已解决,谢谢,不过为什么你们的编译器能通过我的确不行呢?我用的VC6.0

追答

尽量用cpp格式, c++的特性更多一些,

相似回答