1

In Pset 5, the speller problem, we are told to use the following code:

strcopy(new_node -> word, word);

to copy the word from the dictionary into the newly create node, called new_node in this instance. My understanding of the str_copy function is that it works as follows:

strcopy(string destination, string source);

I simply cannot understand why new_node -> word is the string destination. Shouldn't the destination simply be new_node?

3

welcome to the forum.

Assuming new_node is a struct (which I believe is the premise here), then new_node is not a string. In the load walkthrough, the node struct has two elements: word which is a string, and next which is a struct pointer. Therefore, strcopy(new_node -> word, word); would be correct.

Doug Lloyd gives a much better explanation than I ever could in this CS50 video on structs. I think the clarification you seek starts at around 6:40.

2
  • So just for clarification sake, does the notation new_node -> word essentially mean deference new_node (take the value that new_node points to) and put it into word, which is defined as an array of strings?
    – Jvw
    Sep 3 '18 at 13:02
  • Doug Lloyd gives a much better explanation than I ever could in this CS50 video on structs. I think the clarification you seek starts at around 6:40. Sep 3 '18 at 15:42

You must log in to answer this question.

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