I am working on a calendar program, and as part of it, I have a function that takes an integer representing days since sunday, and a cstring, and puts the date of that weekday of the current week into the string. When I compiled the code on Unix systems (under gcc), it works perfectly. However, compiling the same code under gcc on windows (Mingw install from dev-cpp), the function leaves the c-string blank.
Can anyone explain to me why the discrepancy, and how to fix it? The code in question is below:
Line 21: strftime() -- you must specify the number of characters available to write to the target array, which includes the '\0' null. 21strftime(stringout, 11, "%m/%d/%Y", &theTime);
As a side note, this function assumes that the argument string will provide at least 11 characters in the target. You could obviate the problem by guaranteeing that the result is sufficient: