Author |
Message |
Serve Laurijsse #1 / 3
|
 printf -*s format string
What's the difference between the following two format strings? Here, it says "%-*s": printf ("%s%-*s[%s]\n", prompt, 3, "", defvalue); Here, it says "%*s": printf ("%s%*s[%s]\n", prompt, 3, "", defvalue); They both output the same.....
|
Sat, 26 Mar 2005 15:20:15 GMT |
|
 |
Jonas Lindstr? #2 / 3
|
 printf -*s format string
comp.lang.c: Quote: > What's the difference between the following two format strings? > Here, it says "%-*s": > printf ("%s%-*s[%s]\n", prompt, 3, "", defvalue); > Here, it says "%*s": > printf ("%s%*s[%s]\n", prompt, 3, "", defvalue); > They both output the same.....
The flag `-' means that the field is left-justified. In your case, it means that the first printf puts the empty string to the left of the 3 padding spaces, and the second printf puts the empty string to the right of the 3 padding spaces. Jonas -- Use spaces instead of tabs.
|
Sat, 26 Mar 2005 18:16:17 GMT |
|
 |
Zoran Cutur #3 / 3
|
 printf -*s format string
Quote: > What's the difference between the following two format strings? > Here, it says "%-*s": > printf ("%s%-*s[%s]\n", prompt, 3, "", defvalue); > Here, it says "%*s": > printf ("%s%*s[%s]\n", prompt, 3, "", defvalue); > They both output the same.....
The '-' tells printf to left justify the string in the 3 character wide field. As the string passed to %s is an empty one you'll not see any difference, try: printf ("%s%-*s[%s]\n", prompt, 3, "x", defvalue); and printf ("%s%*s[%s]\n", prompt, 3, "x", defvalue); and you'll probably recognize the difference. --
"LISP is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days." -- Eric S. Raymond
|
Sat, 26 Mar 2005 18:21:20 GMT |
|
|
|