"Spiros Bousbouras" <sp****@gmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
marsarden wrote:
code below:
#include <stdio.h>
int main(void)
{
char *aaa[]={"a","b","c"};
printf("%S\n",*aaa); /*the uppercase character S*/
getchar();
}
the stdout give me : "abc"
but ,if i change the "%S" to "%s" /*lowercase s*/
it give me "a" only.
there are no info about %S in c std lib reference,
any one can tell me the truth ?
The S conversion specifier comes from SUSv2 and is
not part of standard C. It has the same meaning as the
ls specifier which is that the argument is of type wchar_t.
I only have a hazy understanding of wide characters so
I can't give you a full explanation why you get output abc
when using the S conversion. The answer may be implementation
specific. It must have something to do with the printf function
interpreting the bytes 'a' , NUL as part of a single wide character
so it doesn't terminate the wide character string there.
References:
GCC:
http://www.gnu.org/software/libc/man...%20Conversions
" %S This is an alias for %ls which is supported for compatibility with the
Unix standard. "
Posix:
http://www.opengroup.org/onlinepubs/...ns/printf.html
1) "S [XSI] Equivalent to ls. "
2) "l (ell)
Specifies that a following d, i, o, u, x, or X conversion specifier applies
to a long or unsigned long argument; that a following n conversion specifier
applies to a pointer to a long argument; that a following c conversion
specifier applies to a wint_t argument; that a following s conversion
specifier applies to a pointer to a wchar_t argument; or has no effect on a
following a, A, e, E, f, F, g, or G conversion specifier. "
Rod Pemberton