更新时间:2023-11-10 09:19:34
root
有一个未定义的值,所以它不会初始化.CreateList
的第二行应该是
root
has an undefined value, so it won't initialize. The second line of CreateList
should be
LIST *root = NULL;
此外,进一步向下显然是项目细节的分配,但是 a) 代码无法捕获分配并将其保存在任何地方,并且 b) 分配的大小应该是 strSize
,不是变量本身的长度.有几种方法可以修复它,但最直接的方法是:
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)