I'm trying to return a string, which is the year.
This code is no where near my GUI layer, as such I'm attempting the following
#define COMPANY_COPYRIGHT "Copyright © " + getYear() + ";
And when it is called I have
void getCopyRight(BSTR* copyRight)
{
CString CopyRightStr = (CString)COMPANY_COPYRIGHT;
}
I'm struggling with my getYear() function
#include <time.h>
const char getYear()
{
time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
timeinfo = localtime (&rawtime);
int year = timeinfo->tm_year + 1900;
char buf[8]; //I think 8 as I expect only 4 characters, each is 2 bit
sprintf(buf,"%d", year); //I can see year shows 2015. But not sure why it's %d because this should be the output format, surely it should be %s but this errors
return buf; //I can see buf shows 2015
}
The above errors with
'return' : cannot convert from 'char[4] to 'const char'
I understand the error message but not what to do. If I add a cast, such as
return (const char)buf; //I can see buf shows 2015
Then it seems to return a single ASCII character, which isn't what I want.
All I want is, instead of returning 2015 as an int, it returns only the value "2015" as a 'string'...