calloc & realloc

Here’s my problem:

I’m creating some arrays using the calloc function.

At some point later in my program I may need to increase the size of these arrays.

I’m wandering if it is possible to reallocate memory for arrays created with calloc, with realloc ?

It says you can in my C programming book, but it gives no examples of how to do it.

Any help would be much appreciated.

Hi!
You can use realloc with calloc just as with malloc…
I think it goes like this:

char * test;

test=(char*)malloc(10);

test=(char*)realloc(test,20)
//Not sure if the realloc call´s syntax is correct look it up in the help…

However realloc is a bitch…Using it has several dangers…The biggest problem is that there is no guarantee that the new allocated space starts at the same memory-address than the old one…Which means that all pointers that are assigned to the array in previous code need to be reassigned after realloc in case the memory location has changed(very likely)…If you don´t reassign them you can get some serios crash…

Greets,XBTC!

[This message has been edited by XBCT (edited 08-06-2000).]