doubt in printf ??

This is a discussion on doubt in printf ?? within the C Programming forums, part of the General Programming Boards category; I m getting only "This is". as output. How ???? Code: printf("This is \x0x65 C \x0x66");...

  1. #1
    C is Sea. I know a drop! ganesh bala's Avatar
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    58

    doubt in printf ??

    I m getting only "This is". as output.

    How ????
    Code:
    printf("This is \x0x65 C \x0x66");

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,734
    What did you expect to get? Note that '\x0' is 0, so you are effectively terminating the string at that point.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    115
    Quote Originally Posted by ganesh bala View Post
    I m getting only "This is". as output.

    How ????
    Code:
    printf("This is \x0x65 C \x0x66");
    is this what you want to see? if not.. tell us

    Code:
    printf("This is %c %c %c", '\x0x65', 'C', '\x0x66' );

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you want to show hex character 0x65, then you should use \x065. As it stands, character constants are malformed. The compiler doesn't detect it, as it is technically a valid string. In $l4xklynx post, it turns to a multi-character constant, and it is probably undefined behaviour exactly what it prints in this case.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IF CONDITION plese help
    By birumut in forum C Programming
    Replies: 12
    Last Post: 03-06-2009, 08:48 PM
  2. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 08:38 AM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  4. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 08:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21