472,951 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 software developers and data experts.

what's the effect of uppercase "S" in printf

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 ?

Sep 12 '06 #1
4 17338
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.

Sep 12 '06 #2
"marsarden" <ar*******@gmail.comwrites:
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 ?
There is no "%S" format in standard C. As far as the standard is
concerned, it can do anything.

<OT>
On one system, the documentation for printf() says:

S (Not in C99, but in SUSv2.) Synonym for ls. Don't use.

"%ls" expects a wchar_t* argument, so again, you're getting undefined
behavior.
</OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 12 '06 #3

"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
Sep 12 '06 #4
marsarden said:
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"
The C language does not make any provision for what happens when you tell
printf to expect a format specifier of a kind it understands, and then fail
to provide one. So the behaviour of your program is undefined, and it could
do anything at all, including (but by no means restricted to) what you say
it did do.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Tobiah | last post by:
Ok, I miss the idiom that my other languages use, something like: while( foo = getmore()){ process(foo); }
6
by: Ken Varn | last post by:
Sometimes when I try to close my managed C++ application, the following dialog displays in Win 2000 Pro: The title of the dialog is "Server Busy". The message is "This action cannot be completed...
5
by: Jarek | last post by:
Hi all! I'm optimizing my C++ multi-threaded application (linux). My application consumes huge amout of memory from unknown reason. There are no memory leaks, or other allocation bugs,...
1
by: blue | last post by:
Looking at code from the following: http://www.gamedev.net/reference/programming/features/enginuity2/page3.asp I'm confused though... CMMPointer(T *o) { obj=0; *this=0;
5
by: junky_fellow | last post by:
Each time i submit some pattern to "google", it shows search took 0.XX seconds for exploring millions of web pages. When i look for efficient ways of searching a string, they always say compare...
2
by: Lasse Edsvik | last post by:
Hello I was wondering if you guys could tell me if: cmd.ExecuteReader(CommandBehavior.CloseConnection); returns a dataset, datatable or what?
1
by: Alan Silver | last post by:
Hello, I have the following line of code in a script... litMsg.Text = Server.MapPath("/"); where litMsg is an ASP.Net Literal control. When I try and run this page, I get the error ... ...
9
by: Dullme | last post by:
i can hardly know what is the code for this. I have researched palindromes, but unfortunately, I only have read about integers not for characters..I need some help..
0
by: diegocami | last post by:
Hi everyone!, I need some directions on how to get my "sweeping bar effect" to work, I´ll try to explain myself: Situation: I have a couple of buttons that should attach (that´s the method I´m...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.