char ***pointer;

Mark J. Bailey root at mjbtn.MFEE.TN.US
Mon Nov 14 10:29:06 AEST 1988


Hello,

I have a question for the C gurus out there.  It has to do with a pointer
declaration and its subsequent use.

I have declared:

	char	***pointer;

Now I know that *ch is generally pointing to the start of a string, ie,
a list (array) of characters.  **ch would be equal to say a list of lists
(or an array of strings, ie, **argv, for example).  ***ch would support
a list of lists of lists of characters.  I suppose this could be associated
with a two dimensional array of strings.

My biggest question here is, when I declare a *ch and then call malloc
to allocate a space for it to point to, I have a string.  I can ch++ to
move up the string.  But when I have **ch, and subsequently, ***ch, do
I have to call malloc to allocate space for more pointers?

For example (using pointer above),

pointer = (char ***) malloc((x)*sizeof(char *));

to allocate space for the *LIST* of pointers I am wanting to use?    

Let me put it another way, I intend to maintain an array of arrays of
strings.  Because of the flexibility of pointers and the fact that I 
don't know ahead of time how many strings and arrays of strings that I  
am going to maintain in my top level array, I use ***pointer instead
of pointer[x][y][z];

Now, when I have a string.  I call malloc to allocate space for that 
string.  I store the string in the new space and then attach it to my
pointer structure.  Can I say **pointer = (char *) newspace?  Then can
I say **pointer++ to move to then next space?  Do I have to create spaces
to **pointer++ to?  A pointer *ch and **ch both occupy 4 bytes on my
in MSDOS.  How does the system view *ch, **ch, and ***ch differently
such that I theoretically could do this?

I apologize for my uncertainty in presenting this, yet I am quite 
uncertain about it.  I don't know exactly how one would view multi-
dimension pointers and I was taking a stab at it here hoping someone
better versed in the concept might shed some light on it for me.
I also know that *ch can be referenced with ch[] and **ch with
ch[][].  I assume ***ch can use ch[][][], but is this legal?  And
it just seems to me that somehow, one would have to ahead of
time allocate space for pointers that you might move to as in
**pointer++ above.  I guess you could view that as pointer[0][0] going
to pointer[0][1].

I feel like I am way off base completely.  Please tell me so if I 
am.  Again sorry for such a long posting.  I would be most appreciative
to any help (and light - PLEASE!!!) anyone might provide.  I know
I don't know what I am talking about! :-)

Mark.

P.S. Email responses would be fine as I am sure this is highly specialized
     and should occupy anymore bandwidth than is necssary.  I will summarize
     and post if warranted.

-- 
Mark J. Bailey                                    "Y'all com bak naw, ya hear!"
USMAIL: 511 Memorial Blvd., Murfreesboro, TN 37129 ___________________________
VOICE:  +1 615 893 4450 / +1 615 896 4153          |         JobSoft
UUCP:   ...!{ames,mit-eddie}!killer!mjbtn!mjb      | Design & Development Co.
DOMAIN: mjb at mjbtn.MFEE.US.TN                       |  Murfreesboro, TN  USA



More information about the Comp.lang.c mailing list