Thread: C file print Issue in Line feed

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    1

    C file print Issue in Line feed

    Hi all,
    I have a problem in printing a line feed character with ASCII value 10(decimal). When Iam trying to print an integer value of 10 in character data type, its printing with carriage return(13 decimal) and line feed(10).
    please suggest me how can I print it only as a Line feed(10 decimal) when I print it as character data type.

    Thanks& Regards,
    Muni.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    You could use a hex escape sequence: "\x0A"
    Code:
    char c = '\x0A';
    const char *s = "Hello World\x0A";
    gg

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you ONLY want a newline to be output, without the normal combination of carriage return (13, 0x0D) then you will need to operate in binary mode on the output file - that will stop the runtime library from adding an automatic carriage return to the newline.

    It makes no difference if you use '\n', '\012' or '\0x0a' to produce that newline - the runtime library is programmed (on DOS/Windows systems) to produce a carriage return on text files whenever it outputs a newline, and remove the carriage return on reading it when it's followed by a newline.

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

  4. #4

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. trying to print a line from a text file
    By kryonik in forum C++ Programming
    Replies: 1
    Last Post: 06-06-2006, 09:14 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM