At the website
http://kerneltrap.org/man/linux/man3p/asctime.3p
there are following errors in the code:
static char wday_name[7][3] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static char mon_name[12][3] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
The numbers [3] must be [4] since there is a '\0' character at the end.
Thomas
Not really. The code works,
Not really. The code works, and is correct. "%.3s" reads at most 3 bytes.
You are wrong. In C99 char
You are wrong.
In C99
char s[3] = "123";
is standards conformant and gives a 3-byte array without terminal '\0'.
You may be right but...
You may be right but some compilers generate an error:
Microsoft Visual C++ 2005 generates error C2117: "An array has too many initializers."
Reason: "No space for the null terminator in a string."
gcc version 3.4.4 generates "error: initializer-string for array of chars is too long"
Thomas