Mail Archives: djgpp/1999/03/06/13:31:12
In article <7bqquf$2d$1 AT news6 DOT svr DOT pol DOT co DOT uk>, Andrew Davidson
<andrew AT lemure DOT freeserve DOT co DOT uk> writes
>>> a little like:
>>>
>>> char *mylist[]= {
>>> "item 1", "item 2", "item 3"
>>> };
>>>
>>> The difference is I don't want a list of pointers to strings, I want
>>> pointers to lists of chars of varying length.
>>
>>Well, you don't say if you are using C or C++.
>>
>>C doesn't know anything about lists of chars of varying length,
>>but, depending on what you mean by that, you CAN do it yourself,
>>with some difficulty. But you need to be more specific.
By "list" I presume you simply mean a row of consecutive
storage spaces, like "FRED" is just {70,82,69,68,0}.
'C' doesn't know anything about a column of rows which aren't
all the same length -- doesn't know about the lengths of
the individual rows, or how to compute a combined size by
adding them up -- so you'd have to handle these things yourself.
In C++ you would define fancy classes to do it; in 'C' you just
fiddle and calculate.
You could define a load of rows of different sizes (they wouldn't
necessarily be stored together in order), then a column with
their addresses in.
But perhaps you want all the data together? The best thing would
be to put it all in a single long row called mydata:
/* VEC0 VEC1 VEC2 */
/* 00 01 02 03 04 05 06 07 08 09 10 11 */
char mydata[]={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12 ....
};
The overall length is the length of this:
int data_length = sizeof(mydata);
The row pointers would go in an array of pointers:
char (*mylist)[]={ mydata+00, mydata+04, mydata+06.... };
And the row-lengths would be stored separately:
int row_length[]={ 4, 2, 6........};
Now use it like this:
if(j < row_length[i] ){ process(mylist[i][j]); };
But don't forget data_length is a different animal from
sizeof(mylist), which is the size in bytes of 5 pointers :-< .
-- -'-._
^-;-^-@@-^-^-^ '-. hoots, mon, there's a moose loose
u- (..)] [ ] | aboot this hoose
| |' | |
""""""""""""""".' .'""""""""""""""news:alt.smoking.mooses
' '
- Raw text -