I am trying to modify some source code as i need to create a filename based on the date however the filename is being created with chinese symbols. I am compiling using nmake for visual studio and unicode.
I am not sure whether this is a code issue or a compiler problem.
Code Extract:
struct tm * timeinfo;
struct tm *__cdecl localtime(const time_t *t);
TCHAR buffer[80];
time_t rawtime;
rawtime = time(NULL);
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, sizeof(buffer), "%d%m%Y%H%M%S", timeinfo);
prd->command[i] = '\0';
LPTSTR t;
for (t = buffer; *t; t++) {
if ((*t != '<') && (*t != '>') && (*t != '\"') &&
(*t != '|') && (*t != '/') && (*t != '\\') &&
(*t != ':'))
prd->command[i++] = *t;
}
//lstrcat(prd->command, buffer);
i = lstrlen(prd->command);
Well after some investigation prompted by the possible duplicate, i now have working code. I had already expected and investigated it was to do with the TCHAR conversion, but not come up with an answer. I did some more investigation on this and came across wcsftime. This seems to have worked and means i do not need to make other modifications to get the code to work and compiles fine in VS2013.
Working code:
struct tm * timeinfo;
struct tm *__cdecl localtime(const time_t *t);
wchar_t buffer[80];
time_t rawtime;
time(&rawtime);
timeinfo = localtime(&rawtime);
wcsftime(buffer, sizeof(buffer), L"%Y%m%d_%H%M%S", timeinfo);
prd->command[i] = '\0';
lstrcat(prd->command, buffer);
i = lstrlen(prd->command);
s++;