From: Dave Bird Newsgroups: comp.os.msdos.djgpp Subject: Re: Array question (a little bit newbie) Date: Sat, 6 Mar 1999 18:01:55 +0000 Organization: very little Message-ID: References: <7bllsm$vap$1 AT news5 DOT svr DOT pol DOT co DOT uk> <36E08691 DOT ED519155 AT jps DOT net> <7bqquf$2d$1 AT news6 DOT svr DOT pol DOT co DOT uk> NNTP-Posting-Host: xemu.demon.co.uk X-NNTP-Posting-Host: xemu.demon.co.uk:158.152.196.209 X-Trace: news.demon.co.uk 920743725 nnrp-06:13927 NO-IDENT xemu.demon.co.uk:158.152.196.209 X-Complaints-To: abuse AT demon DOT net MIME-Version: 1.0 X-Newsreader: Turnpike (32) Version 4.01 Lines: 67 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com In article <7bqquf$2d$1 AT news6 DOT svr DOT pol DOT co DOT uk>, Andrew Davidson 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 ' '