Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!jarthur!nntp-server.caltech.edu!suncub.bbso.caltech.edu!EYCHANER From: eychaner@suncub.bbso.caltech.edu (Amateurgrammer) Newsgroups: comp.lang.c Subject: More 2D array woes... Message-ID: <1991Mar3.235114.12154@nntp-server.caltech.edu> Date: 3 Mar 91 23:51:14 GMT Sender: news@nntp-server.caltech.edu Reply-To: eychaner@suncub.bbso.caltech.edu Organization: Big Bear Solar Observatory, Caltech Lines: 25 Here we go again, warm up the flame guns... Ok, suppose I have an array like char strings[NUMBER][SIZE]; How do I add more strings to this array, i.e. make it larger, portably and easily. I can't realloc it, since it's not a pointer! Argh! Is there some sneaky way to declare it so that I can do what I want, or should I just use char *strings; and a lot of pointer arithmetic? How about char **strings; strings = (char **) calloc (NUMBER, sizeof (char *)); strings[0] = (char *) malloc (SIZE); strings[1] = (char *) malloc (SIZE); ... (I don't care if the 2d array is contiguous or not...) Then strings is a pointer and I can realloc it, allowing me to add more strings! And can I even access them as (strings [string_num]) [string_pos] = 'x'; which becomes *(*(strings + string_num) + string_pos) = 'x'; or does it? I'm not sure.... :-) Glenn Eychaner - Big Bear Solar Observatory - eychaner@suncub.bbso.caltech.edu "You Have the Right to Remain DEAD." -The Simpsons