TIP: Click on subject to list as thread! ANSI
echo: cis.tandy.coco
to: Bill Dickhaus 70325,523 (X)
from: Mark Griffith 76070,41
date: 1990-05-03 06:20:10
subject: #3216-#C arrays

#: 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.

SOURCE: compuserve via textfiles.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.