String Array (again)

Hello,
I had posted on this topic before, but it had a different tack. My problem is (simplified a teeny bit for the forum) is that I have three strings of varying length. I want to reference them in an array, so that I can reference the nth string randomly

I have defined the three strings as separate variables. Then create an array of pointers to the individual strings. Thus, when I want to use (print) a string, I can index the pointer array.

Clear as mud? I hope not. I am sure that I am doing mutiple things wrong in the code below; mainly because it won't compile. Can you take a look and explain where my misunderstanding lies?

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
char MoveString_0[]  ="#0P1500#1P1500#2P1000#3P570#4P1500#5P2400#6P510#8P1500#9P1500#10P1500#11P1400T1000";
char MoveString_1[]  ="#2P1100";
char MoveString_2[]  ="#0P2000 #1P1100 T100";

char* MoveCommand[] =
{
(&MoveString_0) ,
(&MoveString_1) ,
(&MoveString_2)
};

Serial.println( *MoveCommand[1] );
while (-1){};

}

The error I am getting is:

MoveCommandTest:17: error: cannot convert 'char (*)[83]' to 'char*' in initialization

Ditch the & :

char* MoveCommand[] =
{
(&MoveString_0) ,
(&MoveString_1) ,
(&MoveString_2)
};

Or use &MoveString_0[0];

The name of the array without the brackets IS a pointer. So with the extra & there you are trying to take the address of the pointer. OR if you put the brackets and 0 on the end and leave the & then you are taking the address of the first element in the array. It will work either way but I like it better if you just drop the &.

That compiles... Thanks! and thanks for the great explanation, too.

My Mega is being shipped and I can test this on the hardware soon.

So what's the syntax I need when printing (or referencing) the nth string?

Serial.println(moveCommand[n]); should do it. That would be the same as saying Serial.println(moveString_0);

instead of

char MoveString_0[]  ="#0P1500#1P1500#2P1000#3P570#4P1500#5P2400#6P510#8P1500#9P1500#10P1500#11P1400T1000";
char MoveString_1[]  ="#2P1100";
char MoveString_2[]  ="#0P2000 #1P1100 T100";
char* MoveCommand[] =
{
(&MoveString_0) ,
(&MoveString_1) ,
(&MoveString_2)
};

you can simply write it as

char* MoveCommand[] =
{
  "#0P1500#1P1500#2P1000#3P570#4P1500#5P2400#6P510#8P1500#9P1500#10P1500#11P1400T1000",
  "#2P1100",
  "#0P2000 #1P1100 T100"
};

and you can access it as

Serial.println( MoveCommand[1] );