Creating a singly linked list in C

后端 未结 3 1409
攒了一身酷
攒了一身酷 2021-01-13 00:58

I\'m trying to create a singly linked list from an input text file for an assignment. I\'m trying to do it a little bit at a time so I know my code is not complete. I trie

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-13 01:29

    The second malloc allocates memory but its return value is not assigned to anything, so that allocated memory is lost.

    newList is allocated but not initialized, so using a memcpy to copy memory to newList->str will fail since newList->str points to nothing. Probably you wanted the result of the second malloc to be assigned to newList->str, but you forgot it.

提交回复
热议问题