Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
June 07, 2002 Arrays of strings | ||||
---|---|---|---|---|
| ||||
I have been scratching my head trying to figure this out. How to declare a dynamic array of dynamic strings and access then strings. I have tried the following: char[]*[] stringArray; // read from file into char[] tempHolder. It reads in thew string alright as I have succesfully displayed iot // back to the screen. This step could probably be done away with and read staright into the string array. // then copy into string Array stringArray[stringArray.length - 1] = new char[tempHolder.length]; //or char[][] stringArray; stringArray[stringArray.length - 1] = tempHolder; Both produce errors. I have been working on this code for hours. I would like the strings to be dynamic by the way so I'm not sure whether method 1 is the best way to go. ryan |
June 07, 2002 Re: Arrays of strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ryan Michel | "Ryan Michel" <ryan@michel.com.au> wrote in message news:1103_1023449782@news.digitalmars.com... > I have been scratching my head trying to figure this out. How to declare a dynamic array of dynamic strings and char[][] stringlist; stringlist ~= "foo"; stringlist ~= "bar"; stringlist ~= "baz"; for (int i = 0; i < stringlist.length; i++) printf("%.*s\n", stringlist[i]); |
June 08, 2002 Re: Arrays of strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ryan Michel | char[][] stringArray; makes an empty array of strings. So stringArray.length-1 = -1. Accessing stringArray[-1] produces a compile-time error. I also have a problem with strings. What's bad in this? import c.stdio; int main() { char*[3] lines = [ "Per me si va nella citta' dolente,", "Per me si va nell'etterno dolore,", "Per me si va tra la perduta gente." ]; blah(lines); return 0; } void blah(char*[] lines) { for(int i; i < lines.length; ++i) printf('%s' \n, lines[i]); } The compiler says: Assertion failure: 'ie' on line 253 in file 'declaration.c' abnormal program termination Is this a compiler bug? |
June 08, 2002 Re: Arrays of strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | Move the initialized array out of the function. Sean "Dario" <supdar@yahoo.com> wrote in message news:adt6mj$lbq$1@digitaldaemon.com... > char[][] stringArray; > makes an empty array of strings. So stringArray.length-1 = -1. Accessing > stringArray[-1] produces a compile-time error. > > I also have a problem with strings. What's bad in this? > > import c.stdio; > int main() > { > char*[3] lines = > [ "Per me si va nella citta' dolente,", > "Per me si va nell'etterno dolore,", > "Per me si va tra la perduta gente." > ]; > blah(lines); > return 0; > } > void blah(char*[] lines) > { > for(int i; i < lines.length; ++i) printf('%s' \n, lines[i]); > } > > The compiler says: > Assertion failure: 'ie' on line 253 in file 'declaration.c' > abnormal program termination > > Is this a compiler bug? > > |
June 08, 2002 Re: Arrays of strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | Incredible, that's works. Maybe I'll seem stupid, but why can't I write it
in the function?
Moreover, can I write this?:
blah( ["one", "two", "three"] );
"Sean L. Palmer" wrote
> Move the initialized array out of the function.
>
> Sean
|
June 10, 2002 Re: Arrays of strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | "Dario" <supdar@yahoo.com> wrote in message news:adtlvs$14li$1@digitaldaemon.com... > Incredible, that's works. Maybe I'll seem stupid, but why can't I write it in the function? You can, it just needs to be 'static'. It's a bug in the compiler. > Moreover, can I write this?: > blah( ["one", "two", "three"] ); Not yet <g>. |
June 17, 2002 Re: Arrays of strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | > > Incredible, that's works. Maybe I'll seem stupid, but why can't I write it > > in the function? > You can, it just needs to be 'static'. It's a bug in the compiler. > > Moreover, can I write this?: > > blah( ["one", "two", "three"] ); > Not yet <g>. So it is going to be supported, is it in the specs? Where can I found info about it? |
June 18, 2002 Re: Arrays of strings | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | "Dario" <supdar@yahoo.com> wrote in message news:aekb6u$1huf$1@digitaldaemon.com... > > > Incredible, that's works. Maybe I'll seem stupid, but why can't I write > it > > > in the function? > > You can, it just needs to be 'static'. It's a bug in the compiler. > > > > Moreover, can I write this?: > > > blah( ["one", "two", "three"] ); > > Not yet <g>. > > So it is going to be supported, is it in the specs? Where can I found info about it? It'll get supported, but it isn't in the specs yet. -Walter |
Copyright © 1999-2021 by the D Language Foundation