I've spent quite a moment today trying to figure out why a super-simple C function, which reads a text file, doesn't work. I was able to make it work by swapping parameters in calloc
function:
Instead of:
calloc(1, size_of_the_memory_to_allocate)
I did:
calloc(size_of_the_memory_to_allocate, 1)
So instead of 1 element of size 20, I did 20 of size 1.
calloc(size, 1)
Is there any difference in the allocation?
EDIT2:
I guess I was not clear enough with the question, or it was misunderstood. The question was: "Why allocating pointer to pointer using calloc requires swapping arguments?". It wasn't about debugging the code, nor have I asked anyone to run it, it was about how calloc
works. The answer made by @chqrlie is exactly what I was looking for. I guess I have made a mistake of adding any code to the question, and readers concentrated on it, rather than on what I have asked for. So, here's an edit, and now chqrlie's answer fit perfectly. If this still is something that won't help other users, let's just delete the question and be done with it.