dzoey@terminus.umd.edu (Joe Herman) (01/18/91)
From article <9009@uwm.edu>, by tanith@csd4.csd.uwm.edu (Michael D Kretzer): > I don't know whether this question as much to do with OS/2 as with > C programming, You're right, it really belongs in comp.lang.c, but here goes.... > ...to declare 256 pointers to strings, each with 256 bytes allocated. > I was wondering if you could declare this from one command, or if > you have to declare char *Array[256] and then malloc the memory in > a loop for each string. If you do not need the 256 byte arrays to be contiguous with each other, you're much better off using "char *array[256]" and then mallocing memory for each pointer. If, for some reason, you do need the arrays to be contiguous, then malloc a large block of memory (256 x 256) and assign array[x] = &foo[x*256] where 0 <= x < 256. The reason you can not do what you want is that malloc returns a single pointer. You want malloc to return an array of pointers, which is not it's purpose. Oh yes, just to make this somewhat OS/2 relevant, does anyone know if OS/2 2.0 is supposed to be 32 bit? Can we get rid of "huge" arrays then? Have fun, Joe H. U. of Maryland dzoey@terminus.umd.edu P.S. I've directed followups to comp.lang.c -- "Everything is wonderful until you know something about it."