c - Dereferencing pointer to incomplete type error for a structure member -


i have checked other questions similar problems, none of solutions worked case.

the problem in hand is, trying create stack dynamic memory, using struct:

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

however, i'm running trouble in few of functions: specifically, "dereferencing pointer incomplete type". here's erroneous pieces of code:

struct node *temp; temp = (struct stekas*)malloc(sizeof(struct stekas)); /* code */ temp = top; printf("popped out number: %d\n", temp->content); top = top->link; free(temp); 

and here's other function gets error:

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

i'm assuming has pointer not connecting content. i've checked other questions, seemed have poblems struct itself, don't see problems one.

it seems struct node used in these code snippets

struct node *temp; temp = (struct stekas*)malloc(sizeof(struct stekas)); /* code */ temp = top; printf("popped out number: %d\n", temp->content); top = top->link; free(temp); 

and

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

was not defined.

i think mean struct stekas

also both code snippets have other serious errors. example allocated memory , assigned addres pointer temp

temp = (struct stekas*)malloc(sizeof(struct stekas)); /* code */ 

and overwrote pointer. address of allocated memory lost.

temp = top; 

so there memory leak.

or in statement

for (i = top; >= 0; i--) { 

variable has type int while top pointer. assignment = top , decreasing i-- not make sense.

and whet expression temp->content[i] used in printf statement?

printf("%d\n", temp->content[i]); 

content neither pointer nor array. may not apply subscript operator.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -