Printf Issues

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ao the Unstoppable

    #1

    Printf Issues

    Hi. I'm pretty new to C/C++, and I was wondering how to correctly use
    printf and then create a new line. What in printf creates a new line,
    as if it was endl; in cout?

    For example:

    printf ("Hello World!");
    printf ("How are you?");

    How would I make it skip a line to output:

    Hello World!
    How are you?

    ....rather than:

    Hellow World!How are you?

    Thanks.
  • Phlip

    #2
    Re: Printf Issues

    Ao the Unstoppable wrote:
    [color=blue]
    > printf ("Hello World!");
    > printf ("How are you?");
    >
    > How would I make it skip a line to output:
    >
    > Hello World!
    > How are you?
    >
    > ...rather than:
    >
    > Hellow World!How are you?[/color]

    Look up "escape codes" in the index of your least favorite tutorial.

    \n

    And it ain't a feature of printf, it's a feature of string and character
    literals.

    --
    Phlip



    Comment

    • Jack Klein

      #3
      Re: Printf Issues

      On 29 Nov 2004 22:21:56 -0800, cyanbloodbane@g mail.com (Ao the
      Unstoppable) wrote in comp.lang.c++:
      [color=blue]
      > Hi. I'm pretty new to C/C++, and I was wondering how to correctly use
      > printf and then create a new line. What in printf creates a new line,
      > as if it was endl; in cout?
      >
      > For example:
      >
      > printf ("Hello World!");[/color]
      printf ("Hello World!\n");[color=blue]
      > printf ("How are you?");[/color]
      printf ("How are you?\n");[color=blue]
      >
      > How would I make it skip a line to output:
      >
      > Hello World!
      > How are you?
      >
      > ...rather than:
      >
      > Hellow World!How are you?
      >
      > Thanks.[/color]

      The newline escape sequence '\n' works in C++ streams as well.

      --
      Jack Klein
      Home: http://JK-Technology.Com
      FAQs for
      comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
      comp.lang.c++ http://www.parashift.com/c++-faq-lite/
      alt.comp.lang.l earn.c-c++

      Comment

      • rakesh k

        #4
        Re: Printf Issues

        Jack Klein <jackklein@spam cop.net> wrote in message news:<0s4oq0hgk 61el91f9bia946h uoalp7uao8@4ax. com>...[color=blue]
        > On 29 Nov 2004 22:21:56 -0800, cyanbloodbane@g mail.com (Ao the
        > Unstoppable) wrote in comp.lang.c++:
        >[color=green]
        > > Hi. I'm pretty new to C/C++, and I was wondering how to correctly use
        > > printf and then create a new line. What in printf creates a new line,
        > > as if it was endl; in cout?
        > >
        > > For example:
        > >
        > > printf ("Hello World!");[/color]
        > printf ("Hello World!\n");[color=green]
        > > printf ("How are you?");[/color]
        > printf ("How are you?\n");[color=green]
        > >
        > > How would I make it skip a line to output:
        > >
        > > Hello World!
        > > How are you?
        > >
        > > ...rather than:
        > >
        > > Hellow World!How are you?
        > >
        > > Thanks.[/color]
        >
        > The newline escape sequence '\n' works in C++ streams as well.[/color]

        you could use this:

        printf ("Hello World!\nHow are you?");

        '\n' is the newline character in c/c++

        Comment

        • Andrew Koenig

          #5
          Re: Printf Issues

          "Ao the Unstoppable" <cyanbloodbane@ gmail.com> wrote in message
          news:ba964d1e.0 411292221.2d59c 844@posting.goo gle.com...
          [color=blue]
          > Hi. I'm pretty new to C/C++, and I was wondering how to correctly use
          > printf and then create a new line.[/color]

          Why do you want to use printf instead of << ?


          Comment

          Working...