How to add new line in c
In C, you can add a new line to the output using the \n
character. This is called a newline character.
Here are a few ways to add a new line in C:
-
Using
printf
:printf("Hello, world!\n");
The
\n
at the end of the string will print a new line. -
Using
puts
:puts("Hello, world!");
The
puts
function automatically adds a new line at the end of the string. -
Using
fprintf
:fprintf(stdout, "Hello, world!\n");
This is similar to
printf
, butfprintf
allows you to specify the output stream (in this case,stdout
). -
Using
write
:write(1, "Hello, world!\n", 13);
This is a more low-level way to add a new line, using the
write
system call to write to the standard output (file descriptor 1).
Note that the \n
character is not actually a character in the classical sense, but rather a special sequence of characters that tells the terminal to move to the next line. This is why it's often referred to as a "newline" character.