@Salem, this code seems to be working fine and got rid of most of the errors. I also set all global variables to 0/NULL too. It cleared the pointer related leaks and I will be able to fix rest.
...
Type: Posts; User: redworker
@Salem, this code seems to be working fine and got rid of most of the errors. I also set all global variables to 0/NULL too. It cleared the pointer related leaks and I will be able to fix rest.
...
Ok, I was able to make some memory leaks go away by calling free on htable. How do I call free() on resluts?
h_ptr new_element(char *s)
{
h_ptr result = (h_ptr) malloc(sizeof(h_rec));
...
By didn't work I mean it didn't make any difference with my memory leaks errors. I think I need to call free() on results as well to get rid of errors. Tried several things but it making error even...
How does this look:
void freeHash(htable)
{
if (!htable) return;
for (int i=0; i<tsize; i++)
free(htable[i]);
free(htable);
}
So, I need to create a function that iterates (for loop) through the list and then call free()? I will do some research on hash tables and will try if I can do it.
Thanks for the help
@grumpy
Can't really redesign as I am doing an exercise to detect and fix memory leaks. This code was all given and I just want to get rid of memory leaks to get some experience with memory...
Yeah, I though I knew where should i call free() but it didn't work. For example, what do you think when should I call free() on results variable. I tried it on several places and it made it worse....
Hi,
I believe I need to call free on Hash Table, List Elements and Unique words (htable, result etc). I am not sure where and how to call free as pointers are being used. Sorry program is big...
Ah cant believe I did that mistake. Ok now I fixed the code but when I enter 20, it says factorial is -2102132736
but when I enter lower number like 5, it gives me correct answer 120. Whats wrong...
it gives me an error
Hi,
I am working on a program that asks a user to enter a # between 1 to 50 and finds the factorial of that. It uses recursive function to find it.
Here is what I got so far:
...
Hi,
I am working on a program that asks a user to enter a # between 1 to 50 and finds the factorial of that. It uses recursive function to find it.
Here is what I got so far:
include...