0
SYSTEMTIME ConvertStringToSystemTime(const char *dateTimeString) const 
{

    SYSTEMTIME systime;
    memset(&systime, 0, sizeof(systime));
    // Date string should be "dd-MM-yyyy hh:mm:ss:mss"
    auto u = sscanf_s(dateTimeString, "%d/%d/%d%d:%d:%d:%d:%d",
        &systime.wDay,
        &systime.wMonth,
        &systime.wYear,
        &systime.wHour,
        &systime.wMinute,
        &systime.wSecond,
        &systime.wMilliseconds);
    return systime;
}

My whole problem being is that I'm reading a date from a file, which is stored in a string variable, and I need to subtract the current Systemtime to the one read from the file.

And I was trying to sort it out by converting the string to Systemtime, and then get the difference, but after trying out this function, I keep getting that warning error which I must fix but don't know how exactly.

Michael Veksler
  • 8,217
  • 1
  • 20
  • 33
Riad
  • 5
  • 5

2 Answers2

0

In windows, WORD is defined as unsigned short, so it needs %u instead of %d.

Liu Yubo
  • 116
  • 3
0

Use %hu instead of %d.

Explanation: The fields of SYSTEMTIME fields are of type WORD, which is defined as

typedef unsigned short WORD;

Reading type unsigned short requires %hu as described here.

Michael Veksler
  • 8,217
  • 1
  • 20
  • 33