Recently a student asked: > i'm trying to use realloc in my program and i can't seem to get it to > work. i'm trying to expand an ever growning array of pointer to char > > char** out; > out=(char**)realloc(out,1); > I haven't ever used realloc (before just now), but essentially what you have worked for me: (Notice that I didn't have to copy in the old locations.) runner% cat realloct.c #include #include void main(void) { char **out; char **p; out = (char **) malloc(4*sizeof(char*)); out[0] = "Now"; out[1] = "is"; out[2] = "the time"; out[3] = NULL; p = out; while (*p != NULL) printf("%s\n", *(p++)); out = (char **) realloc(out, 7*sizeof(char *)); out[3] = "for all good"; out[4] = "to come to the aid"; out[5] = "of their party"; out[6] = NULL; p = out; while (*p != NULL) printf("%s\n", *(p++)); } runner% lint -m -u realloct.c function returns value which is always ignored printf runner% cc -o realloct realloct.c runner% realloct Now is the time Now is the time for all good to come to the aid of their party