Velocity Reviews > Question in C

Question in C

Joachim Schmitz
Guest
Posts: n/a

 12-29-2010
> Ok, wrong question asked, why: printf("%d", '\11'); gives 9 ?? What
> this \ means ?

'\nnn' is number in octal. Octal 11 is 9 decimal.

Bye, Jojo

BartC
Guest
Posts: n/a

 12-29-2010

"Mateusz_madi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Ok, wrong question asked, why: printf("%d", '\11'); gives 9 ?? What
> this \ means ?

Probably '\11' specifies a character constant with the given numeric code
\11, where 11 is octal notation (why octal, I don't know; maybe everyone
used octal in the 70s).

And 11 in octal is 9.

I don't know how you managed to get S out of it.

--
Bartc

Joachim Schmitz
Guest
Posts: n/a

 12-29-2010
BartC wrote:
> "Mateusz_madi" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Ok, wrong question asked, why: printf("%d", '\11'); gives 9 ?? What
>> this \ means ?

>
> Probably '\11' specifies a character constant with the given numeric
> code \11, where 11 is octal notation (why octal, I don't know; maybe
> everyone used octal in the 70s).
>
> And 11 in octal is 9.
>
> I don't know how you managed to get S out of it.

simple:

case 9: putchar('S');

(taken from the code the OP posted elsethread)

bye, Jojo

Guest
Posts: n/a

 12-29-2010
Ok, I understand.
Thanks for help.

Seebs
Guest
Posts: n/a

 12-29-2010
On 2010-12-29, Mateusz_madi <(E-Mail Removed)> wrote:
> Hi why when i write:
> printf("%c", \11); i get S??

Because the compiler generated code which produced S, apparently.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

Seebs
Guest
Posts: n/a

 12-29-2010
On 2010-12-29, Mateusz_madi <(E-Mail Removed)> wrote:
> That's the whole code:

Okay, the question you wrote then is probably the worst-asked question
I've ever seen on Usenet. What you wrote is totally, completely,
and utterly unlike the actual code in every way.

> char input[]="SSSWILTECH1\1\11W\1WALLMP1";

Okay, so, you have a \11 here.

> case 9 : putchar('S');

Look, you have something that does a putchar('S')!

I think you should consider the possibility that, if you're getting an 'S'
you don't expect, you might want to look closely at the code leading to
it. It says "case 9". Hmm.

> Additionally i have question how: /*case 'E' : case 'L' : continue; */
> works,

Cases fall through, so either case 'E' or case 'L' will hit the continue
statement, which jumps back to the top of the loop.

> and what is the difference between /* case 1 */ and /* case '1'
> */

1 is the integer value 1. '1' is the integer value corresponding to the
numeral 1 in your current character set.

Computers store characters as numbers using some sort of encoding. On
particularly common encoding is ASCII, which provides definitions for
the letters and numbers used in English, plus some punctuation, stored
as values from 0 to 127.

A string in C is just a series of such numbers, terminated by one with
the value 0. In ASCII, the numeral 1 has the value 49, so "case '1'" will
match the numeric value 49... and if you have a string "1", the first
character of that string has the numeric value 49.

In strings, backslashes introduce an "escape sequence". This allows you
to insert special characters in the string that would otherwise be hard
to type. You can use \" to insert a double quote in a string, for instance.
Of particular interest are the hexadecimal and octal escape sequences:

\045 => character whose octal value is 045
\x45 => character whose hexadecimal value is 0x45

0x45 is 4 16s plus a 5, or 69 decimal, and corresponds to 'E' in ASCII.
045 is 4 8s plus a 5, or 37 decimal, and corresponds to '%' in ASCII.

If you have a \ followed by numbers between 0 and 7 inclusive, it
is an "octal escape". So \1 is the value 1, and \11 is the value
(one eight plus one one) = 9.

So the \11 in your string becomes a character with the numerical value 9,
which isn't a printable character, but which 'case 9:' picks up.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

Seebs
Guest
Posts: n/a

 12-29-2010
On 2010-12-29, Ralf Damaschke <(E-Mail Removed)> wrote:
> OK, then I suggest you to study your compiler documentation for
> the meaning of the diagnostic message "S". You apparently know
> little about C, but believe me: the statement above requires a
> diagnostic message and those have to be documented by the
> implementation.

You're talking to "Kenny". Kenny is a liar. He has stated in the past
that there is *nothing* important in this life other than social status.
Because he's a moron, he resents the tendency of this newsgroup to respect
people who know what they're talking about and correct errors. As a result,
he reacts to any correction of errors by declaring them to be "wrong" in
some way.

Thing is, he does this *totally* without regard to facts, which he regards
as unimportant. Since he saw a post "correcting" the OP, he declared by
fiat that the correction was wrong and the OP's description was correct,
so he posted claiming this had happened.

If you interpret this as a claim about the real world and its behaviors, you
have already missed the point of anything Kenny wrote. What he was writing
would have been expressed, by a more competent writer, as:

It offends me that you are telling someone that there is something
wrong with code rather than helping him by answering his question.
Since I am a total ****ing moron whose head is so far up his ass
that I wear Klein bottle sweaters, it has not occurred to me that
it is possible that the code is actually totally buggered, and I'm
going to assume the program works just fine and you're talking
about how it could theoretically fail to work on some machine no
one's ever built, and post supporting the OP's account.

.... Of course, someone self-aware enough to write that wouldn't.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

Seebs
Guest
Posts: n/a

 12-29-2010
On 2010-12-29, Mateusz_madi <(E-Mail Removed)> wrote:
> Ok, wrong question asked, why: printf("%d", '\11'); gives 9 ?? What
> this \ means ?

This is the right question, though totally unrelated to what you said before.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

Guest
Posts: n/a

 12-29-2010
Regards ,
Mateusz

Keith Thompson
Guest
Posts: n/a

 12-29-2010
> Ok, wrong question asked, why: printf("%d", '\11'); gives 9 ?? What
> this \ means ?

Look up "character constants" in your C textbook.

Another good resource is the comp.lang.c FAQ, <http://www.c-faq.com/>.
The FAQ is *not* a good way to learn C from scratch, but it's great
for clearing up the inevitable misunderstandings you'll run into as
you learn.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"