473,804 Members | 3,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 17672
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*******@gmai l.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_Keit h) 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.c omwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.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
3069
by: Tobiah | last post by:
Ok, I miss the idiom that my other languages use, something like: while( foo = getmore()){ process(foo); }
6
16959
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 because the other program is busy. Choose 'Switch to' to activate the busy program and correct the problem." I don't know why this is displayed. I would prefer to disable the display of this message if possible. My app needs to be able to...
5
2778
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, application works well, but on startup it has about 200mb (VmSize). How can I investigate what function/class/other takes so much memory ? I tried to verify sizes of classes using sizeof, but it returns so small values (<100 bytes), there are very little...
1
2233
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
2078
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 your string with the strings in the file one by one. if there are millions of web pages then these algorithms would take considerable amount of time. So, what does google do for searching a pattern. Does it use thousands of parallel computers...
2
1491
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
1842
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 ... System.ArgumentException: Empty path has no directory.
9
4027
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
1363
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 using)different movieclips (one each) to an empty "mc_container" on stage. There is an attached movieclip by default (let´s call it "mc_1") . So when the user clicks on the "button_2" for example, there´s a bar that "sweeps" over (or covers...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10578
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.