Thanks All! My brain hurts after reading and tyring to understand
your explanations. I think i get this now, or at least my program
works now
Thanks again
Something else to make your brain hurt: An array has elements of a
fixed size.
So you cannot have an array of strings of different
length. With pointers to strings, those pointers have a fixed size.
You can have an array of those, then.
char *name[] = { "one","two","three" };
Spiral your way outward beginning towards the right of 'name'. You
hit '[]'. "'name' is an array." You circle back over and hit 'char
*'. "'name' is an array of 'char *'."
Your element count is unspecified between '[]'. The initializer list
will determine the count. The count is 3. "'name' is an array of
'char *' with 3 elements."
The initializer list will determine the initial values.
'"one"' itself has type 'char[4]' (but do not attempt to modify its
contents, in general). When used as an initializer value, '"one"'
yields a 'char *' to the first element ('o'). '"two"' yields a
pointer to its 't', etc. Thus, you have your 'char *' elements for
your 'name' array.
Visually, it might look like this in memory:
First string literal, nul-terminated:
00: ['o'] 01: ['n'] 02: ['e'] 03: [0]
Second string literal, nul-terminated:
04: ['t'] 05: ['w'] 06: ['o'] 07: [0]
Third string literal, nul-terminated:
08: ['t'] 09: ['h'] 10: ['r'] 11: ['e'] 12: ['e'] 13: [0]
The 'name' array of 'char *' with 3 elements:
14: [00] ??: [04] ??: [08]
'??' because the address depends on the size of a 'char *'. This is
merely an example, obviously.
(The addresses are silly in that
they start at 0 and happen to be "cooked" to be contiguous.)
Hope it helps.