linked list - Error when declaring variable in C -
i have private node class keeps track of key, value, , next node, linking nodes together.
however, when try declare numitems, , head of list error stating never declared.
typedef struct nodeobj{ char* key; char* val; struct nodeobj* next; } nodeobj; typedef nodeobj* node; node newnode(char* x, char* y){ //makes node n , returns n // x->key, y->val next->null } //the main class typedef struct listobj{ node head; int numitems; } listobj; list newlist(void){ list l = malloc(sizeof(listobj)); assert(l!=null); l->head = null; l->numitems = 0; return l; } //whenever try reference head or numitems errors stating //that haven't been declared?
the errors are
list.c: in function'find': list.c:59:11: error: 'head' undeclared(first use in function) node n = head list.c:60: note: use option -std=c99 or -std=gnu99 compile code
the same error gets repeated whenever reference numitems or head, , use -std=c99 compile
there several thing might go wrong here.
list l = malloc( sizeof(listobj) ); // should pointer type => list* l = ....
list l , listobj different types writing list* l = malloc( sizeof( listobj ) ) not have desired effet
Comments
Post a Comment