使用 C 的堆栈项目头文件中的指针错误

问题描述

我目前正在做一项关于使用头文件、源文件和主文件在 C 语言中制作堆栈的作业。我正在尝试我的教授编写的这段代码,但我无法解决文件中的错误代码: 堆栈.h

#ifndef stack_H
#define stack_H

#include <stdio.h>
#include <stdbool.h>

#define Nil 0
#define MaxEl 10

typedef int infotype;
typedef int address;

typedef struct{
    infotype T[MaxEl+1]; 
    address TOP;         
} Stack;

#define Top(S) (S).TOP //the error is this line
#define InfoTop(S) (S).T[(S).TOP]

/*Body Prototype*/
/*** Constructor***/
void CreateEmpty(Stack *S);

bool isEmpty(Stack S);

#endif // stack_H

stack.c

#ifndef stack.c
#define stack.c

#include "stack.h"
#include <stdio.h>

void CreateEmpty(Stack *S){
    Top(S)=Nil;
}

bool isEmpty(Stack S){
    return Top(S)==Nil;
}
#endif

main.c

#include <stdio.h>
#include <stdlib.h>
#include "stack.h"

int main()
{
    Stack S;
    CreateEmpty(&S);

}

错误说:'S' is a pointer; did you mean to use '->'?

我很确定我几乎完全复制了教授的代码,但错误仍然存​​在。有关如何解决此问题的任何建议?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)