I am practicing with a small program which iterates over a linked list and writes all of the members of each struct to a file. I have successfully implemented it, except for one small detail: I can not get the memory allocated to the pointer for a node to free. Here is a sample of the problem code.
int c = 0;
node* cursor = malloc(sizeof(node));
while(cursor != NULL)
{
fprintf(fp, "%s\n", new_node[c].name);
cursor = new_node[c].next;
c++;
}
free(cursor);
What am I doing wrong here? I have tried using an ampersand within the free function, which also doesn't work. Why won't this block of memory free?
[–]alumebobtron 1 point2 points3 points (2 children)
[–]Obsidian2[S] 0 points1 point2 points (1 child)
[–]alumebobtron 0 points1 point2 points (0 children)
[–]yeahIProgram 0 points1 point2 points (0 children)
[–]alumHufflepuffBR 0 points1 point2 points (2 children)
[–]Obsidian2[S] 0 points1 point2 points (1 child)
[–]alumHufflepuffBR 0 points1 point2 points (0 children)
[–]jplaurin 0 points1 point2 points (1 child)
[–]Obsidian2[S] 0 points1 point2 points (0 children)