0

Does anyone knows about the function calloc in c ? It seem that it does not behave as it is supposed.

I have a pointer *ptr on an array of a structure with two members : an int and ant int *t. when I apply calloc on *ptr to cet more space, the contents of each existent *t change.

7th Jun 2017, 9:22 AM
Tamene Samuel
Tamene Samuel - avatar
2 Antworten
0
I believe it is because when you use calloc it will not only increase the pointer, it will create a new memory address of the desired size with all the bytes zeroed. If this is the case, you can use memcpy to pass the data from the old pointer to the new pointer.
7th Jun 2017, 9:43 AM
Igoor Silver
Igoor Silver - avatar
0
sorry it was realloc not calloc
7th Jun 2017, 9:47 AM
Tamene Samuel
Tamene Samuel - avatar