// thus on Tue, 20 Jan 1998 15:02:22 -0500, Jamie virtually wrote:
> Antioch wrote:
>> Ok, so i've come across this thing that i can't identify in any of my C
>> books and my head's starting to hurt from banging it on the wall:
>> char **list_of_something;
>> Looking through the code, it seems to store arrays of strings. However,
>> I'm trying to figure out why they used something like this instead of
>> creating a structure or just a regular character array.
>> Can anyone identify this little deal and explain its usefullness? I would
>> appreciate it very very very very very very very much.
> You're right in that it is an array of strings, or more accurately an
> array of pointers to chars. This would be equivalent to writing the
> following:
> char *list_of_something[];
No it wouldn't, although C has the equivalence of arrays and pointers, do
not confuse them as such (comp.lang.c FAQ).
char **data
This is a pointer to a pointer of type char.
char *data
This is a pointer of type char (also known as a string).
char **data is normally used to make a 2 dimensional array.
data points to this ,--> **data
| / ,--> *(*data + 1)
V / /
[PTR] *data -------> [f] [i] [r] [s] [t] [\0]
|
[PTR] *(data + 1) -> [s] [e] [c] [o] [n] [d] [\0]
|
[PTR] *(data + 2) -> [t] [h] [i] [r] [d] [\0]
char *data[] is an array of pointers of type char, it is only when you feed
this to a function does it become a pointer to a pointer of type char.
d.
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST