c - Inserting New Node -
here function of program i'm writing more familiar nodes.
it creates new node , inserts information code field , points existing first node. assigns head newly created node;
unfortunately it's giving me incompatible types new_node->location = code;
typedef char librarycode[4]; typedef struct node { librarycode location; struct node *next; } node; void insertfirstnode(librarycode code, node **listptr) { node *new_node; new_node=malloc(sizeof(node)); new_node->location = code; new_node->next = *listptr; *listptr = new_node; }
librarycode
typdef
ed char [4]
. can't assign 1 array another, you'll need memcpy
or strcpy
data 1 array other.
a simpler example of what's going on:
void foo() { char a[4]; char b[4]; = b; }
compiling gives error:
in function ‘foo’: error: incompatible types when assigning type ‘char[4]’ type ‘char *’ = b; ^
you can see you're trying assign pointer array, incompatible types.
the typedef char librarycode[4];
not idea anyway. if you're going keep fixed-size buffer string in node, ditch typedef
it's clear you're doing. also, never pass char [4]
by value function. strings, pass const char*
.
Comments
Post a Comment