Question in C

Discussion in 'C Programming' started by Mateusz_madi, Dec 29, 2010.

  1. Mateusz_madi

    Mateusz_madi Guest

    Hi why when i write:
    printf("%c", \11); i get S??
     
    Mateusz_madi, Dec 29, 2010
    #1
    1. Advertising

  2. In article
    <>,
    Mateusz_madi <> wrote:

    > Hi why when i write:
    > printf("%c", \11); i get S??


    That's odd, I get "error: stray '\' in program"

    How about posting a copy of a complete compilable program.
     
    Mark Storkamp, Dec 29, 2010
    #2
    1. Advertising

  3. Mateusz_madi

    Coos Haak Guest

    Op Wed, 29 Dec 2010 09:42:11 -0800 (PST) schreef Mateusz_madi:

    > Hi why when i write:
    > printf("%c", \11); i get S??


    You don't, the program will not compile because of a stray '\'.

    --
    Coos
     
    Coos Haak, Dec 29, 2010
    #3
  4. In article <1r8b8h7qw4v7e.zdqydjbbhi4e$>,
    Coos Haak <> wrote:
    >Op Wed, 29 Dec 2010 09:42:11 -0800 (PST) schreef Mateusz_madi:
    >
    >> Hi why when i write:
    >> printf("%c", \11); i get S??

    >
    >You don't, the program will not compile because of a stray '\'.


    Interesting that you say that...

    On my system, I get S, just like the OP.

    --
    One of the best lines I've heard lately:

    Obama could cure cancer tomorrow, and the Republicans would be
    complaining that he had ruined the pharmaceutical business.

    (Heard on Stephanie Miller = but the sad thing is that there is an awful lot
    of direct truth in it. We've constructed an economy in which eliminating
    cancer would be a horrible disaster. There are many other such examples.)
     
    Kenny McCormack, Dec 29, 2010
    #4
  5. Mateusz_madi

    Mateusz_madi Guest

    That's the whole code:

    ----------------------
    #include<stdio.h>

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

    main()
    {
    int i,c;


    for( i=2; (c=input)!='\0'; i++){
    switch(c){
    case 'a' : putchar('i'); continue;
    case '1' : break;
    case 1 : while( (c=input[++i])!='\1' && c!='\0');
    case 9 : putchar('S');
    case 'E' : case 'L' : continue;
    default : putchar(c); continue;
    }
    putchar(' ');
    }
    putchar('\n');
    }
    ------------------------
    Additionally i have question how: /*case 'E' : case 'L' : continue; */
    works, and what is the difference between /* case 1 */ and /* case '1'
    */

    Regards
     
    Mateusz_madi, Dec 29, 2010
    #5
  6. (Kenny McCormack) wrote:

    > [...] Coos Haak <> wrote:
    >>Op Wed, 29 Dec 2010 09:42:11 -0800 (PST) schreef Mateusz_madi:
    >>
    >>> Hi why when i write:
    >>> printf("%c", \11); i get S??

    >>
    >>You don't, the program will not compile because of a stray '\'.

    >
    > Interesting that you say that...
    >
    > On my system, I get S, just like the OP.


    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.

    -- Ralf
     
    Ralf Damaschke, Dec 29, 2010
    #6
  7. In article <-h.de>,
    Ralf Damaschke <> wrote:
    > (Kenny McCormack) wrote:
    >
    >> [...] Coos Haak <> wrote:
    >>>Op Wed, 29 Dec 2010 09:42:11 -0800 (PST) schreef Mateusz_madi:
    >>>
    >>>> Hi why when i write:
    >>>> printf("%c", \11); i get S??
    >>>
    >>>You don't, the program will not compile because of a stray '\'.

    >>
    >> Interesting that you say that...
    >>
    >> On my system, I get S, just like the OP.

    >
    >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.
    >
    >-- Ralf


    Gotcha!

    --
    One of the best lines I've heard lately:

    Obama could cure cancer tomorrow, and the Republicans would be
    complaining that he had ruined the pharmaceutical business.

    (Heard on Stephanie Miller = but the sad thing is that there is an awful lot
    of direct truth in it. We've constructed an economy in which eliminating
    cancer would be a horrible disaster. There are many other such examples.)
     
    Kenny McCormack, Dec 29, 2010
    #7
  8. Mateusz_madi

    Mateusz_madi Guest

    Ok, wrong question asked, why: printf("%d", '\11'); gives 9 ?? What
    this \ means ?
     
    Mateusz_madi, Dec 29, 2010
    #8
  9. Mateusz_madi

    Ben Pfaff Guest

    Mateusz_madi <> writes:

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


    In this case, it introduces an octal constant. Octal 11 is
    decimal 9.
    --
    Ben Pfaff
    http://benpfaff.org
     
    Ben Pfaff, Dec 29, 2010
    #9
  10. Mateusz_madi

    Mateusz_madi Guest

    HA! That mae sense, so when i put in the test "something...\12" values
    \xx will mean the same as 012??
    Regards
     
    Mateusz_madi, Dec 29, 2010
    #10
  11. Mateusz_madi wrote:
    > 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
     
    Joachim Schmitz, Dec 29, 2010
    #11
  12. Mateusz_madi

    BartC Guest

    "Mateusz_madi" <> wrote in message
    news:...
    > 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
     
    BartC, Dec 29, 2010
    #12
  13. BartC wrote:
    > "Mateusz_madi" <> wrote in message
    > news:...
    >> 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
     
    Joachim Schmitz, Dec 29, 2010
    #13
  14. Mateusz_madi

    Mateusz_madi Guest

    Ok, I understand.
    Thanks for help.
     
    Mateusz_madi, Dec 29, 2010
    #14
  15. Mateusz_madi

    Seebs Guest

    On 2010-12-29, Mateusz_madi <> 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.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, Dec 29, 2010
    #15
  16. Mateusz_madi

    Seebs Guest

    On 2010-12-29, Mateusz_madi <> 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.

    To answer the rest:

    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 /
    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, Dec 29, 2010
    #16
  17. Mateusz_madi

    Seebs Guest

    On 2010-12-29, Ralf Damaschke <> 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 fucking 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 /
    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, Dec 29, 2010
    #17
  18. Mateusz_madi

    Seebs Guest

    On 2010-12-29, Mateusz_madi <> 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.

    I have also already answered it in another post.

    -s
    --
    Copyright 2010, all wrongs reversed. Peter Seebach /
    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, Dec 29, 2010
    #18
  19. Mateusz_madi

    Mateusz_madi Guest

    Thanks Seebs for answering my questions that was helpfull.
    Regards ,
    Mateusz
     
    Mateusz_madi, Dec 29, 2010
    #19
  20. Mateusz_madi <> writes:
    > 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) <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"
     
    Keith Thompson, Dec 29, 2010
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sean
    Replies:
    1
    Views:
    629
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  2. =?Utf-8?B?UnlhbiBTbWl0aA==?=

    Quick Question - Newby Question

    =?Utf-8?B?UnlhbiBTbWl0aA==?=, Feb 14, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    702
    Iain Norman
    Feb 16, 2005
  3. =?Utf-8?B?YW5kcmV3MDA3?=

    question row filter (more of sql query question)

    =?Utf-8?B?YW5kcmV3MDA3?=, Oct 5, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    981
    Scott Allen
    Oct 6, 2005
  4. Philip Meyer
    Replies:
    0
    Views:
    451
    Philip Meyer
    Nov 30, 2003
  5. Bit Byte
    Replies:
    1
    Views:
    889
    Teemu Keiski
    Jan 28, 2007
Loading...

Share This Page