Creating a singly linked list in C

后端 未结 3 1399
攒了一身酷
攒了一身酷 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:17

    root has an undefined value, so it won't initialize. The second line of CreateList should be

    LIST *root = NULL;
    

    Also, further down there is allocation apparently for the details of the item, but a) the code fails to capture the allocation and save it anywhere, and b) the size of the allocation should be strSize, not the length of the variable itself. There are several ways to fix it, but the most straightforward would be:

    newList->str = (char *)malloc(strSize);
    if (newList->str == NULL)
    

提交回复
热议问题