Hi, I'm trying to create a clock class that uses an rtc.
The rtc provides me the time date etc as a series of integers.
I have a method in my clock class called getTime(char theTimeAsACharArray)
I would like this method to formulate the integers into an array of chars and return it to the caller.
I know I can't return a char array from a function per say, I have to pass it the array by reference, so that's what I'm trying to do.
This is ok except within my array I'm trying to use snprintf to formulate the char array.
This does not work. If I directly manipulate the char array(don't use snprintf), ie
theTimeAsACharArray = '0';
theTimeAsACharArray = '9'; etc it works fine.
This is my code for the function :
void getTime(char theTimeAsACharArray)
t = rtc.time();
snprintf(theTimeAsACharArray, sizeof(theTimeAsACharArray), "%02d-%02d-%04d%02d:%02d:%02d",
t.date, t.mon, t.yr, t.hr, t.min, t.sec);
//which I call like so :
But buf is alway empty?
snprintf seems to do the job until it goes out of scope, I have played around with this till the cows come home, read up on pointers and apassing by ref ect but can't seem to nail it, I think it has something to do with me misunderstanding how snprintf works.
Please could someone help me