Thread: Printing \n on the screen in C

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688

    Printing \n on the screen in C

    I cannot belive I have to ask this, but nono of my C books tell me how to so this, and I have attempted to #define it with no avail.

    Basicly I want '\n' to show in a printf statement. Every attempt I have made just makes the newline chacter work as it should and prints a new line.

    Basicly, the output I want is:

    In C use the \n escape character to print a newline

    I have tried these:

    Code:
    printf("In C use the \"\n\" ecscape character to print a newline\n");
    
    printf("In C use the %s escape character to print a newline\n"); /*defined NL*/
    I have googled the problem but nothing is helping, Am I really dont think this is even possible, as the compiler always reads the \n and prints the newline as it should. Am I correct?
    Double Helix STL

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	printf("To print '\\n' to the screen, escape the '\\' char with a double '\\' like this: \"\\\\n\".  ;)\n");
    	return 0;
    }

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Thanks MacGyver Appreciated mate
    Double Helix STL

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Code:
    puts( "In C use \\n to print an \n but use \\\\n to print an \\n." );

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Really all you have to know is your escape sequences.

    Code:
    \\ = \
    \n = LF
    \r = CR
    \b = backspace
    ... etc
    Then it's really logic from there...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Faster way of printing to the screen
    By cacophonix in forum C Programming
    Replies: 16
    Last Post: 02-04-2009, 01:18 PM
  2. printing in screen
    By imagetvr in forum C++ Programming
    Replies: 2
    Last Post: 08-16-2008, 10:35 AM
  3. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 04:56 PM
  4. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM
  5. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM