0

In load, when I assign the word I loaded from dictionary to new_node, I originally used

new_node->word = new_word

but an error told me that it is non assignable. However, when I use strcpy it works, but why? Thanks in advance.

1 Answer 1

2

This is the way strings work in C. Because a string in C is an array of chars, you can only initialize it during the declaration. If you want to change its contents after the initialization, or if you declared it without initialization, you need to manually copy the new string into the old string char by char, and to not forget about the final '\0'. Or you can use strcpy(), which basically does this all for you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .