You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
The text was updated successfully, but these errors were encountered: