Hi again, been a while since I've posted although I do read alot here.
I need a little help, I want to get away from using Strings and go with char arrays.
I can figure most of it but I got this bit of code that I can't seem to avoid using a string.
String cyear;
char cyear1[8];
cyear = year();
cyear.toCharArray(cyear1, sizeof(cyear1));
year() comes from the rtc and this works fine, I just wonder if theres any way to put
it into the char array without first putting it into a string.
What type of data does year() return ?
year() is one of the fields that comes from getting the time date from the rtc.
The string year() has 4 digits of the current year.
I then use the cyear1[] char array to make a year folder on the SDcard.
Like so,
if (!SD.exists(cyear1)){
SD.mkdir(cyear1);
SD.chdir(cyear1);
lcd.setCursor(0, 1);
lcd.print (" Created year ");
delay1();
OK. so maybe year() is an int?
cause if I try..
year().toCharArray(cyear1, sizeof(cyear1));
I get..
error: request for member 'toCharArray' in 'year()', which is of non-class type 'int'
OK. so maybe year() is an int?
Yes it is.
You can use itoa() to convert the integer into a null terminated character array.
char buf[5];
itoa(year(), buf, 10);
Thanks for that, It works.. Sometimes it's just that simple. But then I've chased my tail around for days cause I was missing a bracket.