#: 3236 S10/Tandy CoCo
03-May-90 06:20:10
Sb: #3216-#C arrays
Fm: Mark Griffith 76070,41
To: Bill Dickhaus 70325,523 (X)
Bill,
Bruce Mackenzie's method is good, i.e.;
char **sp; /* declare a pointer to a character pointer */
sp=calloc(MAX,sizeof(char *)); /* assign it to the base of a block of
memory to hold the pointer array */
You'll need to know the MAX number of elements before you do this tho. If you
need some more after you made a array, then calloc() another larger array and
copy the pointers from the first into the second and then free() the first
array.
However, you will also need to malloc() enough memory to hold each element of
the array before you copy anything into it. If the elements are strings, then
you'll need to allocate strlen() + 1 for each since strlen() doesn't count the
\0 at the end. If you don't, it will work but you might have a weird bug, or
you'll stack overflow sometime during the program run.
Mark
There is 1 Reply.
|