I think I have some issue understanding string and string literal.
This is what I learned from my class, when passing to a function, const char * indicates this is a string literal, while char * indicates a string.
Suppose I have a struct declaration:
struct node{
char *name;
struct node *next;
};
and a function, this is the function I want to implement:
void load_buffer(struct node *input_node, char *input_name);
This function is supposed to assign input_name to the struct's member name.
My confusion comes from here. Within the body of load_buffer, should I write:
input_node->name = input_name;
Or I should use strcpy/strncpy to do this?
strcpy(input_node->name, input_name);// Suppose it's safe in this case.
To summarize, I am not sure if I should use direct assignment or strcpy family functions to assign a string/string literal to the member of my struct.
Thanks for help. :)