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:
printf("格式化字符串", 变量1, 变量2, ...);
To use theprintf()
function for newline output, you can use the newline escape sequence\n
:
printf("换行输出\n"); // 输出 "换行输出" 并换行
putchar() function
putchar()
The function outputs a single character to standard output. To achieve newline output, you can use the newline ASCII code 10:
putchar(10); // 换行输出
Usage Demonstration
The following code snippet demonstrates these two newline outputs Method:
#include int main() { // 使用 printf() 函数换行输出 printf("换行输出 1\n"); // 使用 putchar() 函数换行输出 putchar(10); printf("换行输出 2"); return 0; }
Output result:
换行输出 1 换行输出 2
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!