Home > Article > Backend Development > How to wrap output in c language program
In C language, there are two methods for newline output: using the printf() function and using the newline escape sequence \n. Use the putchar() function and use ASCII code 10 for the newline character.
How to use C language program to wrap output
In C language, wrap output can realize the end of text line Wrap, that is, create a new line. There are two commonly used methods to achieve newline output:
printf() function
printf()
function The format is:
<code class="c">printf("格式化字符串", 变量1, 变量2, ...);</code>
To use the printf()
function for newline output, you can use the newline escape sequence \n
:
<code class="c">printf("换行输出\n"); // 输出 "换行输出" 并换行</code>
putchar() function
putchar()
The function outputs a single character to standard output. To achieve newline output, you can use the newline ASCII code 10:
<code class="c">putchar(10); // 换行输出</code>
Usage Demonstration
The following code snippet demonstrates these two newline outputs Method:
<code class="c">#include <stdio.h> int main() { // 使用 printf() 函数换行输出 printf("换行输出 1\n"); // 使用 putchar() 函数换行输出 putchar(10); printf("换行输出 2"); return 0; }</code>
Output result:
<code>换行输出 1 换行输出 2</code>
The above is the detailed content of How to wrap output in c language program. For more information, please follow other related articles on the PHP Chinese website!