new_node
should be accessed as a pointer and not an instance.
try new_node->val
instead of new_node.val
response to edited question
As you have changed from char val
to char *val
you will need additional processing:
- allocate memory for
*val
:new_node->val=(char*)malloc(sizeof(char))
- assignment will need to dereference the pointer :
*(new_node->val)="a"
- Print statement should also dereference the pointer :
printf("%c",*(new_node->val))
- you should free the
val
pointer before freeingnew_node
:free(new_node->val)