Home » C programming language

How to print multiple line messages using single printf in C language?



It’s a very basic program, where we learn printing multiline messages through printf() statement using '\n' escape sequence.
Submitted by Manju Tomar, on September 10, 2017

Example:

    This is line 1.
    This is line 2.
    This is line 3.

Let’s see how to print these lines using separate printf statements?

Consider the program:

#include <stdio.h>

int main()
{

    printf("This is line 1.");
    printf("This is line 2.");
    printf("This is line 3.");
   
    return 0;
}

Output

This is line 1.This is line 2.This is line 3.

Escape sequence (New Line - "\n")

"\n" is a new line character, which can be used anywhere within the message written in printf() statement.

Write first line "This is line 1." Then write "\n" again write "This is line 2." And then write "\n" and so on...

#include <stdio.h>

int main()
{

    printf("This is line 1.\nThis is line 2.\nThis is line 3.");
   
    return 0;
}

Output

This is line 1.
This is line 2.
This is line 3.

As I wrote above that this is a very basic program, and helpful for those who are starting to learn C program, there are other escape sequences too, you may learn from here:

Thanks for reading...






Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.