-
trouble with structs..
Given the code:
Code:
typedef struct {
int item;
struct node *next;
} node;
int
main(int argc, char *argv[]) {
node *n = malloc(sizeof(node));
n->item = 5;
n->next = n;
return 0;
}
(yes, I'm aware that in this configuration, the node will be pointing to itself).
Why does gcc (OSX 10.5) report the following error:
josephus.c: In function 'main':
josephus.c:15: warning: assignment from incompatible pointer type
Thanks!
-
Did you ever define a struct node? You have an anonymous struct that you have typedef'ed as a node. Perhaps try
Code:
typedef struct Node {
int item;
struct Node *next;
} node;