Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a newline using printf?

How do I add a new line to a print command using printf?

printf "I want this on a new line!" 

I thought it would be something like this but it didn't work

printf "/n I want this on a new line!/n" 

Thanks in advance for the help!

like image 392
Nightlock32 Avatar asked May 21 '12 22:05

Nightlock32


People also ask

How do I add a new line in printf?

The printf statement does not automatically append a newline to its output. It outputs only what the format string specifies. So if a newline is needed, you must include one in the format string. The output separator variables OFS and ORS have no effect on printf statements.

What is the format to print newline in a printf?

The sequence \" translates as a literal double-quote; it is escaped with a backslash so that printf knows to treat it as a literal character, and not as the end of the FORMAT string. \n is the sequence for a newline character, and tells printf to begin a new line and continue the output from there.

How do you add a new line in C?

The newline character ( \n ) is called an escape sequence, and it forces the cursor to change its position to the beginning of the next line on the screen. This results in a new line.


1 Answers

To write a newline use \n not /n the latter is just a slash and a n

like image 155
petschekr Avatar answered Oct 14 '22 02:10

petschekr