Go Down

Topic: Text Array (Read 1 time) previous topic - next topic

KirAsh4

Is there a way to do something like this:
Code: [Select]
char sNames[7] = {'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sun'};

Serial.print(sNames[1]);


And have it output 'Mon' ?

Seems silly to have to write a switch case to figure out what to print.

lloyddean

#1
Jan 08, 2013, 06:34 am Last Edit: Jan 08, 2013, 06:41 am by lloyddean Reason: 1
Code: [Select]

char* sNames[] = {
     "Sun" // 0
   , "Mon" // 1
   , "Tue" // 2
   , "Wed" // 3
   , "Thu" // 4
   , "Fri" // 5
   , "Sat" // 6
};

Serial.print(sNames[1]);

KirAsh4


AWOL

Quote
Is there a way to do something like this:
Code:

char sNames[7] = {'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sun'};

NB - double quotes and a pointer.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

guix

Or,
Code: [Select]

char sNames[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sun"};

Go Up