![]() |
Memory allocation problem, don't know what's wrong
Code:
#include<stdio.h>Case 2 reads the entire file and puts everything in memory. I'm having a problem here: Code:
memptr = realloc(memptr, c*sizeof(registo));Code:
*** glibc detected *** ./ex1: realloc(): invalid next size: 0x0804a170 ***Code:
memcpy(memptr[c].proprietario, registo.proprietario, sizeof(registo.proprietario));Anyone have any idea what's wrong and what should I do instead? |
Re: Memory allocation problem, don't know what's wrong
Before anyone mentions it, I just noticed it multiplies by zero on the first loop... stupid me.
I'm having other problems now but I'll try to fix them first now that I figured how what this problem was : p |
Re: Memory allocation problem, don't know what's wrong
I'm having another problem now, I switched the code that loads to the memory to a separate function, this one:
Code: Cpp
And in main, I call it as soon as the program opens it: Code: Cpp
I get a segmentation fault on those fwrites in main(), I know the problem is somewhere in the use of pointers but isn't the memptr supposed to be passed as a pointer to the function? |
| All times are GMT +5.5. The time now is 20:59. |