In C language programming, you can use the following methods to wrap lines: escape character '\n' puts() function fputs() function fputc() function (print character by character, use character '\n' to print Line break)
How to use C language programming to wrap line
In C language programming, you can use the following Way to wrap:
1. Escape character '\n'
Using escape character '\n' is the most commonly used way to wrap line. It will move the cursor to the beginning of the next line. For example:
<code class="c">printf("第一行\n"); printf("第二行");</code>
Output:
<code>第一行 第二行</code>
2. puts() function
puts() function will print a string and wrap it automatically. For example:
<code class="c">puts("第一行"); puts("第二行");</code>
Output:
<code>第一行 第二行</code>
3. fputs() function
fputs() function is similar to puts() function, but it can Prints a string to the specified file. For example:
<code class="c">FILE *fp = fopen("output.txt", "w"); fputs("第一行\n", fp); fputs("第二行", fp); fclose(fp);</code>
Output (output.txt):
<code>第一行 第二行</code>
4. fputc() function
fputc() function can print character by character into the file. To print a newline character, use the character '\n'. For example:
<code class="c">FILE *fp = fopen("output.txt", "w"); fputc('第', fp); fputc('一', fp); fputc('行', fp); fputc('\n', fp); fputc('第', fp); fputc('二', fp); fputc('行', fp); fclose(fp);</code>
Output (output.txt):
<code>第一行 第二行</code>
The above is the detailed content of How to wrap lines in c language programming. For more information, please follow other related articles on the PHP Chinese website!