473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 17478
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.