I am a developer coming from python. I have a C header file but when I try to use it, I get a lot of syntax errors.
I am using MSVC compiler.
here is the code:
stack.h
typedef struct stack
{
void* data;
Stack* next;
} Stack;
Stack* _stack_init(Stack* s, void* item);
void _stack_push(Stack* s, void* item);
void _stack_pop(Stack* s);
stack.c:
#include <stdlib.h>
typedef struct stack
{
void* data;
struct stack* next;
} Stack;
Stack* _stack_init(Stack* s, void* item) {
Stack* new_stack = (Stack*) malloc((sizeof(Stack)));
new_stack->data = &item;
}
void _stack_push(Stack* s, void* item) {
if (s->next != NULL) {
_stack_push(s->next, item);
}
Stack* new_item = _stack_init(s, item);
s->next = new_item;
}
void _stack_pop(Stack* s) {
if (s->next == NULL) return s;
else _stack_pop(s->next);
}
and here is the error:
g:\progs\c\csv_reader\libs/structures/stack.h(4): error C2061: syntax error: identifier 'Stack'
g:\progs\c\csv_reader\libs/structures/stack.h(5): error C2059: syntax error: '}'
g:\progs\c\csv_reader\libs/structures/stack.h(7): error C2143: syntax error: missing '{' before '*'
g:\progs\c\csv_reader\libs/structures/stack.h(7): error C2143: syntax error: missing ')' before '*'
g:\progs\c\csv_reader\libs/structures/stack.h(7): error C2059: syntax error: 'type'
g:\progs\c\csv_reader\libs/structures/stack.h(7): error C2059: syntax error: ')'
g:\progs\c\csv_reader\libs/structures/stack.h(8): error C2143: syntax error: missing ')' before '*'
g:\progs\c\csv_reader\libs/structures/stack.h(8): error C2143: syntax error: missing '{' before '*'
g:\progs\c\csv_reader\libs/structures/stack.h(8): error C2059: syntax error: 'type'
g:\progs\c\csv_reader\libs/structures/stack.h(8): error C2059: syntax error: ')'
g:\progs\c\csv_reader\libs/structures/stack.h(9): error C2143: syntax error: missing ')' before '*'
g:\progs\c\csv_reader\libs/structures/stack.h(9): error C2143: syntax error: missing '{' before '*'
g:\progs\c\csv_reader\libs/structures/stack.h(9): error C2059: syntax error: ')'
I can't see any syntax errors personally. can anyone explain to me about this error? Thanks for your help in advance!