[英]Program is free of memory errors, valgrind tests failed - CS50 pset5 speller
[英]CS50 pset5 Speller - :( program is free of memory errors valgrind tests failed; see log for more information
我得到:
112 bytes in 2 blocks are still reachable in loss record 1 of 1:
(file: dictionary.c, line: 112)
line: 112: node *n = malloc(sizeof(node));
这是我的代码:
bool load(const char *dictionary)
{
FILE *f = fopen(dictionary, "r");
if (f == NULL)
{
unload();
return 1;
char word [LENGTH + 1];
int coun = 0;
while (fscanf(f, "%s", word) != EOF)
{
node *n = malloc(sizeof(node));
if (n == NULL)
{
unload();
return 0;
}
strcpy(n->word, word);
n->next = NULL;
coun ++;
int index = hash(n -> word);
n -> next = table[index];
table[index] = n;
}
words_size = coun;
fclose(f);
return 1;
}
任何帮助,将不胜感激。
这是您应该解决的问题:-
load
返回一个bool
而不是int
,如在第 7、18 和 30 行中,您将返回1
,它是一个int
值。 您应该根据情况return false
或true
。 试试这个,如果它不起作用,请留下您的错误评论。 来帮忙! :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.