A single
char is not a buffer. You probably want something like
char buffer[19];
(Your filenames are 18 characters long.)
You must of course also fix the buffer references:
get_utc_time(buffer);
logfile.open(buffer);
Finally, on line 22, you are using the non-standard function
sprintf_s(), which provides some safety by specifying the maximum number of characters to fill. As it is, you have specified 80, which is more than
buffer contains.
You should specify the same number as is the number of characters in
buffer. The recommended way of doing this is to provide that information as argument:
1 2 3 4 5 6
|
void get_utc_time(char *buffer, size_t size)
{
SYSTEMTIME st;
GetSystemTime(&st);
sprintf_s(buffer, size, "%04d%02d%02dT%02d%02dZ.log", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute);
}
| |
and
|
get_utc_time(buffer,sizeof(buffer));
| |
BTW, I fixed an error in your first format specifier -- as you want a four-digit date value the specifier needs to be "%04d".
Hope this helps.