char array help

I am fairly new to coding and arduino. I am trying to have arduino write "On" or "Off" to a char variable depending on state of digital out pin. I keep getting invalid array assignment. Can someone explain to me why my code doesn't work? Thanks in advance

char RelayState[] = "ukn";   //Relay State
char Ron[] = "On ";          //Relay On
char Roff[] = "Off";         // Relay off
int val = 22;
int ledPin =  13;    // LED connected to digital pin 13


void setup()   {                
  // initialize the digital pin as an output:
  Serial.begin(57600);
  pinMode(ledPin, OUTPUT);     
}



void loop()                     
{
  digitalWrite(ledPin, HIGH);   // set the LED on
 val = digitalRead(ledPin);
 Serial.print("val ");
 Serial.println();
 Serial.print(val);
 Serial.println();


if (val == 1)
{RelayState = Ron;}
delay(3000); 
}

Arrays are groups of logically linked memory addresses. You can not assign one group of memory addresses to another group of memory addresses.

You can copy what’s in one group of logically linked memory addresses (one array) to another in several ways. All depend on knowing how much memory is to be copied, to where.

Your arrays are dynamically sized, although they all end up the same size (4 chars long).

for(int i=0; i<4; i++)
{
   RelayState[i] = Ron[i];
}

There is also the memcpy function and strcpy functions that can be used. How to use them is left as an exercise in RTFM for you.

Thanks for the reply, I will give it a try. Even though the arrays are dynamically sized i made them all 4 chars long since i got some earlier messages about arrays not being the same size.

Just so I understand your code. basically its replacing each char of the 4 char array one by one right?

Yes. The strcpy and memcpy functions implement the loops inside the functions.

Thanks I will look at those functions as well.

Thanks for the help.

@PaulS: Couple of things here:

Arrays are groups of logically linked memory addresses.

I think you may be confusing arrays (collections of data items with sequential memory addresses) with lists (groups of linked memory addresses).

You can not assign one group of memory addresses to another group of memory addresses.

Not strictly true; structures can be directly assigned, without resorting to "memcpy" or "for" loops.

For the purposes of illustrating why the "array = array" assignment worked, I think my explanation was OK. I was thinking sequential when I typed linked. I though about changing it, but, I decided that the difference wasn't that important.