Precision modifier when used with %s, should not pad the result with spaces. However, it does in the little kernel library.
char *temp = “hello”;
char result[20];
snprintf (result, sizeof(result), “%.10s”, temp); // Notice the dot after the % sign
printf(“%s\n”, result);
Expected output
hello
Observed output
hello
In essense, snprintf is padding spaces when it should not be with a precision modifier used with strings.
At least, it doesn’t on my Ubuntu 12.04 x86_64 system, and also shouldn’t according to the man page.
Precision modifier when used with %s, should not pad the result with spaces. However, it does in the little kernel library.
Expected output
hello
Observed output
hello
In essense, snprintf is padding spaces when it should not be with a precision modifier used with strings. At least, it doesn’t on my Ubuntu 12.04 x86_64 system, and also shouldn’t according to the man page.