D - Arrays of strings
- Ryan Michel (14/14) Jun 07 2002 I have been scratching my head trying to figure this out. How to declar...
- Pavel Minayev (9/10) Jun 07 2002 a dynamic array of dynamic strings and
- Dario (23/23) Jun 08 2002 char[][] stringArray;
- Sean L. Palmer (4/27) Jun 08 2002 Move the initialized array out of the function.
- Dario (5/7) Jun 08 2002 Incredible, that's works. Maybe I'll seem stupid, but why can't I write ...
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
Jun 07 2002
"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 declarea 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]);
Jun 07 2002
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?
Jun 08 2002
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?
Jun 08 2002
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
Jun 08 2002
"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>.
Jun 10 2002
itIncredible, that's works. Maybe I'll seem stupid, but why can't I writein the function?You can, it just needs to be 'static'. It's a bug in the compiler.So it is going to be supported, is it in the specs? Where can I found info about it?Moreover, can I write this?: blah( ["one", "two", "three"] );Not yet <g>.
Jun 17 2002
"Dario" <supdar yahoo.com> wrote in message news:aekb6u$1huf$1 digitaldaemon.com...writeIncredible, that's works. Maybe I'll seem stupid, but why can't IitIt'll get supported, but it isn't in the specs yet. -Walterin the function?You can, it just needs to be 'static'. It's a bug in the compiler.So it is going to be supported, is it in the specs? Where can I found info about it?Moreover, can I write this?: blah( ["one", "two", "three"] );Not yet <g>.
Jun 18 2002









"Pavel Minayev" <evilone omen.ru> 