[C Tutorial 4] More on Displaying Output Text

/* this tutorial teaches how to move to a new line while printing text to output */

As we’ve seen in the previous tutorial, the printf function is used to display something as the output. Now, suppose we need to display the following :

Hello Sweety!
How are you?

We now need our program to go to the next line after printing Hello Sweety! Writing two different printf’s won’t work. A special keyword “n” (without the inverts) is used to do this. Printf takes n as an instruction to move to the next line.

The Program:

#include <stdio.h>
#include <conio.h>

int main()
{
printf(Hello Sweety!\nHow are you?);
getch();
return 0;
}

Also, to leave a line between the two statements, i would add nn. Now look at the following images to see how the n works.
The first image is the same program written above. In the second image, we move to the next line after printing How are you?

same_line


Also Check Out

Discuss - No Comments

No comments yet. Why not add one below?

Add a Comment

Your email address will not be published. Note marked required (*) fields.

Contact Durofy

For job openings, contact us at jobs@durofy.com | For any other info including business and advertising, contact us at dev@durofy.com

Durofy on Blackberry

Download the Durofy App to get updates on your Blackberry: To download, click here