Dereferencing pointer to incomplete type in stack

I have checked the other questions with similar problems, but none of the solutions worked for my case.

The problem in hand is, I am trying to create a stack with dynamic memory, using this struct:

struct stekas{
    int content;
    struct stekas *link;
} *top = NULL;

However, I’m running into trouble in a few of my functions: Specifically, “Dereferencing pointer to incomplete type”. Here’s the erroneous pieces of code:

struct node *temp;
temp = (struct stekas*)malloc(sizeof(struct stekas));
/* some code */
temp = top;
printf("Popped out number: %dn", temp->content);
top = top->link;

And here’s the other function that gets the error:

int i;
struct node *temp;
/* some code */
for (i = top; i >= 0; i--) {
printf("%dn", temp->content[i]);

I’m assuming it has something to do with the pointer not connecting to the content. I’ve checked other questions, they seemed to have poblems with the struct itself, but I personally don’t see any problems with this one.

Source: c#

Leave a Reply