expected identifier before '1' attempting to initialize and use an array

New to arduino tables and arrays. attempting to use the weekday number (0,1,2,3,4,5,6) to derive the day name (e.g., use the 0 to get the name "Sunday"). Compile result is this error message: "expected identifier before '1' "

The code:
</>
int goLed = 7;
int nogoLed = 8;
char dayname[10] = ['1' , '1' , '1' , '1' , '1' ,
'1' , '1', '1' , '1' , '1'];
int search_Argument = -1;
void setup() {
Serial.begin(9600);
pinMode(goLed, OUTPUT);
pinMode(nogoLed, OUTPUT);
digitalWrite(goLed, HIGH);
digitalWrite(nogoLed, HIGH);

dayname[10] = "111111111";
}
void loop() {
search_Argument++;
if (search_Argument > 6) {
digitalWrite(nogoLed, HIGH);
} else {
if (search_Argument == 0) { char dayname[10] = 'Sunday ';}
if (search_Argument == 1) { dayname[10] = 'Monday ';}
if (search_Argument == 2) { dayname[10] = 'Tuesday ';}
if (search_Argument == 3) { dayname[10] = 'Wednesday';}
if (search_Argument == 4) { dayname[10] = 'Thursday ';}
if (search_Argument == 5) { dayname[10] = 'Friday ';}
if (search_Argument == 6) { dayname[10] = 'Saturday ';}
}
digitalWrite(goLed, HIGH);
Serial.println(dayname);
}

char dayname[10] = ['1' , '1' , '1' , '1' , '1' ,
                    '1' , '1', '1' , '1' , '1'];

The list of values goes in { }, not [ ]

  dayname[10] = "111111111";

This line of code attempts to set element 10 of the dayname array to a string. Eelemt 10 does not exist, nor can you set a single char element to a string

      char dayname[10] = 'Sunday   ';

This is an an attempt to set element 10 to a multi character char but a char can only have one character so 2 errors

This may give you some inspiration

int goLed = 7;
int nogoLed = 8;
char * dayNames[] = {"Sunday", "Monday", "Tuesday"};  //add as many more as you need


void setup()
{
  Serial.begin(115200);
  for (int dayNum = 0; dayNum < 3; dayNum++)
  {
    Serial.println(dayNames[dayNum]);
    if (strcmp(dayNames[dayNum], "Monday") == 0)
    {
      Serial.println("It's Tuesday today");
    }
  }
}

void loop()
{
}

An extended version

int goLed = 7;
int nogoLed = 8;
char * dayNames[] = {"Sunday", "Monday", "Tuesday"};  //add as many more as you need
const byte NUMBER_OF_DAYS = sizeof(dayNames) / sizeof(dayNames[0]);

void setup()
{
  Serial.begin(115200);
  show();
  show();
}

void loop()
{
}

void show()
{
  for (int dayNum = 0; dayNum < NUMBER_OF_DAYS; dayNum++)
  {
    Serial.print(dayNum);
    Serial.print(" ");
    Serial.println(dayNames[dayNum]);
    if (strcmp(dayNames[dayNum], "Monday") == 0)
    {
      Serial.println("Tuesday has been renamed to Bobday");
      dayNames[dayNum] = "Bobday";
    }
  }
  Serial.println();
}

It can always be useful to share the solution so other people that encounter the same problem can learn from it.

I can see that you made an attempt to use code tags but it did not work out. One way to do it

Type
** **[code]** **

Paste your code after that
Type
** **[/code]** **
after the pasted code

Alternative if you're a mouse junk

Click the </> icon in the left top ( not: type </> :wink: ); it will put the above code tags in the post for you and next you can paste your code in between the tags.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.