My buf doesn't output anything

Hello,
I'm a student and i'm learing arduino. This is for a school project and i need to get the month out of DATE. I wanted to do it with a buf but doesn't output anything... What am i doing wrong or is there an easier way to get the month into a char?
For some context the ultimated goal is to get the month but in a number so DATE outputs:
Jun 4 2022 if i'm not mistaken. I would like to get the month number so Jun = sixth month so i would like to get 6. I wanted to put it in a buf and than use an array to get the correct number. I hope it is somewhat understandable. I would really appreciate some help! Thanks in advance.

This is what i have now:

char monthBuf[30];

String compileDate = __DATE__;

char firstCharMonth = compileDate[0];
char secondCharMonth = compileDate[1];
char thirdCharMonth = compileDate[2];



void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);


  strcpy(monthBuf, firstCharMonth);
  strcat(monthBuf, secondCharMonth);
  strcat(monthBuf, thirdCharMonth);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(monthBuf);
}

firstCharMonth is a char, not a string, so you can't use strcpy.

Hi thanks for replying. But what should i use instead or can i convert firstCharMonth into a string?

char monthBuf[30];

char compileDate [] = __DATE__;

void setup() 
{
  Serial.begin(1000000);

  memcpy (monthBuf, compileDate, 3);
  monthBuf [3] = '\0'; // Not necessary /here/ - it's already zero.
  Serial.println(monthBuf);
}

void loop() 
{}

1 Like

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