How To Print Multiline Message Using Single Printf In C Programming ?

Prashant | Sun, 14 Jun, 2020 | 123

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

In this tutorial we will learn to use printf to print multiline using escape sequence.

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.

 

 

 

 

 

 

Related Articles :- 

1Introduction And Getting Started With C

2Basic Of C Language

3. Why We Should Use C Language

4. Applications Of C Programming

5. Basic Rules For Writting C Program

6. Keywords In C Language

7. Comments In C Programming

8. Tokens In C

9. Difference Between Int Main And Void Main

10. C Processor And Macros

11. Variables In C

12. Types Of Variables In C

13. Difference Between Local And Global Variable

14. Difference Bwtween Auto / Extern / Static Variable

15. Constant In C

16. How To Access Global Variable Using Extern Keyword In C

17. Exit And Return Staterment In C

18. Print Float Value Upto N Decimals In C Programming

19. How To Print Multiline Message Using Single Printf In C Programming ?

20. What Value Returned By Scanf Function In C Language ?

21. What Value Is Returned By Printf And Scanf In C

22. What Do 'Lvalue' And 'Rvalue' Mean In C/C++?

23. Errors In C Programming ?

0 comments
Leave a comment