Menu

#15 arrays of strings and specifying chars

v1.0_(example)
closed
5
2007-05-04
2007-04-27
No

I would like to create an array of string, for example

names[] = {"amy","ben","chris","dave","eve"};

I have tried

- "string names[] = {"amy", ... "eve"};

- string names[];
ArrayInit(names,"long_name",5);
name[0] = "amy"

- string names[];
ArrayInit(names,"long_name",5);
StrReplace(names[0],0,"amy");

- string names[];
char stemp[];
char ch;
string abacab= "abcd";

task main()
{
int i;
ch = abacab[1];
ArrayInit(stemp,ch,6);
ArrayInit(names,stemp,4);
names[0] = "amy"

but none of these seem to work.

Also can I use 'a' to specify the character a (=97)?
or do I use "a"? Neither seem to work in ArrayInit(stemp,'a',6) or ArrayInir(stemp,"a",6);

Discussion

  • John Hansen

    John Hansen - 2007-05-04
    • labels: --> Installation Problems
    • milestone: --> v1.0_(example)
    • assigned_to: nobody --> afanofosc_99
    • status: open --> closed
     
  • John Hansen

    John Hansen - 2007-05-04

    Logged In: YES
    user_id=661666
    Originator: NO

    Unfortunately, there is a bug in the NXT firmware which makes it impossible to work with nested arrays (which is what an array of string happens to be). To create and initialize an array of string you can use this code:

    string myStrings[];

    ArrayInit(myStrings, "", 4);
    myStrings[0] = "test";
    myStrings[1] = "test2";
    myStrings[2] = "test3";
    myStrings[3] = "test4";

    But because of the bug in the standard NXT firmware this does not work properly.

    There is a bug in the support for character constants such as 'a' which is making it not work properly in the ArrayInit statement. I will fix that in the next beta release.