I get:
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));
This is my code:
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;
}
Any help would be appreciated.
Here's something u should fix:-
load
returns a bool
not int
, as in line 7, 18 and 30 you are returning 1
which is an int
value. you should instead do return false
or true
as per the situation. try this, if it doesnt work, leave a comments of your error. Here to help! :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.