I'm trying to implement a brackets balance checker with stack, and I can't seem to shake off this
Error
tempCodeRunnerFile.c: In function ‘main’:
tempCodeRunnerFile.c:26:20: error: dereferencing pointer to incomplete type ‘struct StackRecord’
26 | S = malloc(sizeof(*S));
|
Here's the code:
balance.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "stack.h"
void main()
{
struct StackRecord *S;
char str[500], c;
int l, i;
S = malloc(sizeof(*S));
while (1) {
.............
.............
return;
}
stack.c
#include "stack.h"
#include "fatal.h"
#include <stdlib.h>
#define EmptyTOS ( -1 )
#define MinStackSize ( 5 )
struct StackRecord
{
int Capacity;
int TopOfStack;
ElementType *Array;
};
.............
.............
stack.h
typedef int ElementType;
/* START: fig3_45.txt */
#ifndef _Stack_h
#define _Stack_h
struct StackRecord;
typedef struct StackRecord *Stack;
int IsEmpty( Stack S );
int IsFull( Stack S );
Stack CreateStack( int MaxElements );
void DisposeStack( Stack S );
void MakeEmpty( Stack S );
void Push( ElementType X, Stack S );
ElementType Top( Stack S );
void Pop( Stack S );
ElementType TopAndPop( Stack S );
#endif /* _Stack_h */
/* END */
I only put the important parts that cause the issue. It makes no sense since everything seems correct:/
gcc -Wall -Wextra -g. You could want to have some flexible array member