I wish to define a list of months names and access it when printing a report.

Array was defined as follows:

const char months []= {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'};

for (int i=0; i<=11; i++) {



I was looking for help under Arrays in Arduino documentation didn't give, as far as I found, any explanation for such case, but arrays of int

Appreciate any help.

  • 3
    I just want to point out that Arduino uses C++. Straightforward questions like this, about how to create and access arrays can be answered by doing a C++ tutorial. There is nothing particularly special about the fact that the code is running on an Arduino.
    – Nick Gammon
    Nov 30 '18 at 20:06
  • @NickGammon - thank you for your answer. I'm aware of that, but still I did not find any explanation for such case.
    – Guy . D
    Nov 30 '18 at 20:10
  • 1
    Very good. I try to define and access this list without any success - I suggest for future questions you are more explicit about the problem. I see that I can actually define the array the way you did it without error, but I can see that you would have problems printing it because you used single quotes rather than double quotes. It helps to explain what "without success" actually means. If I said "I tried to bake a cake, without success" how would you advise me? A different recipe? A different technique? A better oven? Better ingredients?
    – Nick Gammon
    Dec 1 '18 at 5:49
  • I'll rewrite it.
    – Guy . D
    Dec 1 '18 at 5:55
  • @NickGammon - question is now re-written. Hope it is more undrestandable and not "off-topic"
    – Guy . D
    Dec 1 '18 at 6:01

You are almost there:

  • Use a char* instead of char, a char can only contain one character
  • Use " instead of ' (Thanks Juraj)

Then you get:

const char* months[] =
 {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  • Just fixed :-), found this computer has Arduino installed Nov 30 '18 at 17:27
  • 1
    The timelib uses progmem and a single string for short names and multiplies the index with 3: github.com/PaulStoffregen/Time/blob/master/DateStrings.cpp
    – Jot
    Nov 30 '18 at 17:34
  • @Jot that's also possible, than you just need a function to retrieve the three characters; btw, I didn't see any different in using PROGMEM in my code, maybe it helps if it is just one string (would save 48 bytes). Nov 30 '18 at 17:38
  • 2
    const char* regards[] ={"Thank", "you","very","much!!"};
    – Guy . D
    Nov 30 '18 at 18:26
  • @Guy.D You're welcome Dec 1 '18 at 10:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.