Thread: Spacing between printf statements

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    92

    Spacing between printf statements

    Hello I was just wondering how I could leave a line between printf statements. For the code below.

    Code:
    printf("Hello\n");
    printf("How are you?\n");
    The output will appear on the screen as
    Code:
    Hello
    How are you?
    but I want it appear it as
    Code:
    Hello
    
    How are you?
    I would like to skip 1 or more lines. I would appreciate any help anyone can give.

  2. #2
    Registered User 00Sven's Avatar
    Join Date
    Feb 2006
    Posts
    127
    Code:
    printf("Hello\n\nHow are you?\n");
    '\n' is the newline character.
    Windows XP Home Edition - Dev-C++ 4.9.9.2
    Quote Originally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
    int fflush(FILE *stream)
    On an output stream, fflush causes any buffered but unwritten data to be written; On an input stream, the effect is undefined. It returns EOF for a write error, and zero otherwise. fflush(NULL) flushes all output streams.
    board.theprogrammingsite.com

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Try using another newline:

    Code:
    printf("Hello\n\n");
    printf("How are you?\n");

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    There's a function for just this very thing! Call it with an empty string:
    Code:
    puts( "" );



    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    putchar('\n');

    !!
    If you understand what you're doing, you're not learning anything.

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Code:
    std::cout << std::endl;
    No, wait...

    Oh! If you want to add an extra new line in the output, just put it in the source code! Change:
    Code:
    printf("Hello\n");
    printf("How are you?\n");
    to
    Code:
    printf("Hello\n");
    
    printf("How are you?\n");
    Right? Right!?!
    Last edited by SlyMaelstrom; 08-03-2006 at 01:10 AM.
    Sent from my iPadŽ

  7. #7
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Code:
    printf("Hello\n         <spaces until output wraps to next line>");
    printf("How are you?\n");
    Just don't change the width of your terminal window!
    If you understand what you're doing, you're not learning anything.

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Code:
    {
      int num;
    
      printf("Hello\n");
      do { num = rand(); } while(num != '\n');
      putchar(num);
      printf("How are you?\n");
    }
    extraline.c:5 - WARNING: You are an idiot.

    Last edited by itsme86; 08-03-2006 at 01:23 AM.
    If you understand what you're doing, you're not learning anything.

  9. #9
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Yeah!! You forgot int main( );

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, 09:48 PM
  2. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 09:38 AM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05: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, 09:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM