hi ppl,
i have this problem with reallocating memory. First to mention that I'm a beginner
so the problem is, when i do this :
Code:
typedef struct xxx{
char **test;
} XX;
XX *var;
var = (XX *)malloc(sizeof(XX))
var->test = (char **)malloc(sizeof(char *));
//and then in the loop i would like to extend my var->test
while(){
var->test = (char **)realloc(var->test,20*sizeof(char *));
}
it does not work (Segmentation fault) if i allocate the sizeof(char *) in the beginning and then try to realloc the pointer by 20 ( keap in mind that a already have some data in the var->test[i] (i = 0..2) )
Code:
var->test = (char **)realloc(20*sizeof(char *))
but if i allocate the (
Code:
var->test = (char **)malloc(20*sizeof(char *))
) in the beginning then it works (at least i think so).
how do U reallocate the size of the pointer to a char pointer so that i can keap adding characters to my arrays
thank you
baxy