Extracting the weekday into an array.

Hi I got troble by extraction an array from an array.

static int WeekdayNr;

String     Weekday;

char dayOfTheWeek[12] ;

char daysOfTheWeek[8][12] = {"Noday","Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

char dayOfTheWeek[12] ;

Wereas 

  Weekday = daysOfTheWeek[WeekdayNr];          // works well

  dayOfTheWeek = daysOfTheWeek[WeekdayNr];  // returns exit status 1 invalid array assignment

Who knows how to code it right?
Thank you.

Use strcpy()

Another common method is not to copy the char array, but to set a pointer to point to the particular element you want. I’ve seen that method used in several of the time related libraries that have functions to return the text for days or months.

static int WeekdayNr;

char * dayOfTheWeek;

char daysOfTheWeek[8][10] = {"Noday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup() {
  dayOfTheWeek = daysOfTheWeek[WeekdayNr];
}

void loop() {
}

You should use:

char* Days[9]{Noday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, \0}

So you have to use Days[1] for Sunday and Day[7] for Saturday.

ArnavPawarAA:
You should use:

char* Days[9]{Noday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, \0}

So you have to use Days[1] for Sunday and Day[7] for Saturday.

There is no difference with RIN67630's original array. Except that yours probably will bot compile due to missing "s. Why do you have \0 at the end?

The correct syntax would be

const char * daysOfTheWeek[8] = {"Noday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

That will save you a very slight amount of memory, because it only uses as much memory as needed to store the text, but adds two bytes per string as storage for the pointer.

david_2018:

> char * dayOfTheWeek;

Thank you, declared that way it works!