Im unsure if there is any error in my recursion in unloading/unload to free all memory. (But i doubt so because help50 tells me all my memory were freed- 367,084 allocs, 367,084 frees)

I checked similar problems in stackexchange and i believe it got to do with initialising all my node pointers to NULL right after malloc. 1) Firstly, is this a problem? 2) Didnt i already solve the problem by initializing to NULL? (did i do something wrong here?) 3) Can calloc do the same at the similar/faster speed as a whole?

Any help would be very much appreciated.

[removed spoiler code per academic honesty guidelines]


The issue lies in how you are initializing your nodes.

for (int i=0; i<27; i++)

What is x on that line? Pay special attention to your counting variable in the loop.

To answer your question about calloc, calloc will give you initialized (to zero) memory, which means you don't have to do the initialization loop. I would expect it to be slightly faster (but shouldn't be any slower).

  • Ah it even took me 10minutes to think about what is wrong about the x. Added a line to initialise isWord to false as well. Thanks!
    – Yan Bo Pei
    Jul 9 '18 at 4:08
  • Took me about that long too! :) Can you please accept my answer so we can remove this from the unanswered queue?
    – curiouskiwi
    Jul 9 '18 at 10:08

Setting a pointer to null is only done after the pointer is freed, just as an extra precaution. Maybe use something like calloc(1, sizeof(node)); when setting up your nodes.

It sets the memory to 0x000 instead of NULL, which may help you! And maybe only set the pointer to null after freeing it.

  • Hmm i always thought when you free the pointer, you can no longer access it? Then how do we set it to NULL ?
    – Yan Bo Pei
    Jul 9 '18 at 4:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .