Subj : Re: strange string pointer to strings...? To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Fri Sep 30 2005 11:55 am Thomas Maeder [TeamB] wrote: >Bob Gonder writes: > >>>/* list of words and meanings */ >>>char *dic[][40] = { >>> "atlas", "A volume of maps.", >> >> This would more properly be written >> >> char *dic[] = { >> "atlas", "A volume of maps.", >> "car", "A motorized vehicle.", >> "telephone", "A communication device.", >> "airplane", "A flying machine.", >> >> 0,0 /* null terminate the list */ >> }; > >Better yet > >char const *dic[][40] = { Now, see... that looks a lot like a two dimensional array of pointers to me. Perhaps typedef struct{char entry[40];} dic_entry; dic_entry const * dic[] = { If you want a literal array, just const char dic[][40] = { A one-dimensional array of [40 char] entities. In fact, I just compiled this and set the dump view of debug to dic, and saw a whole bunch of zeros between dic2 and dic3 (about 30 pointer's worth). The only zeros between dic and dic2 are the nulls. typedef struct{char entry[40];} dic_entry; /* An array of 10 pointers */ dic_entry*dic[] = { "atlas", "A volume of maps.", "car", "A motorized vehicle.", "telephone", "A communication device.", "airplane", "A flying machine.", 0,0}; /* An array of 10 pointers */ char const *dic1[] = { "atlas", "A volume of maps.", "car", "A motorized vehicle.", "telephone", "A communication device.", "airplane", "A flying machine.", 0,0}; /* One array of 40 pointers, zero-filled */ char const*dic2[][40] = { "atlas", "A volume of maps.", "car", "A motorized vehicle.", "telephone", "A communication device.", "airplane", "A flying machine.", 0,0}; /* so we can see the end of the array */ char const*dic3[] = {1,2,3,4}; /* 10 asciz strings ocupying 40 bytes each */ char const dic5[][40] = { "atlas", "A volume of maps.", "car", "A motorized vehicle.", "telephone", "A communication device.", "airplane", "A flying machine.", 0,0}; .