How to wrap lines in c language programming

下次还敢
Release: 2024-04-05 00:06:22
Original
576 people have browsed it

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 wrap lines in c language programming

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>
Copy after login

Output:

<code>第一行
第二行</code>
Copy after login
Copy after login
Copy after login
Copy after login

2. puts() function

puts() function will print a string and wrap it automatically. For example:

<code class="c">puts("第一行");
puts("第二行");</code>
Copy after login

Output:

<code>第一行
第二行</code>
Copy after login
Copy after login
Copy after login
Copy after login

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>
Copy after login

Output (output.txt):

<code>第一行
第二行</code>
Copy after login
Copy after login
Copy after login
Copy after login

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>
Copy after login

Output (output.txt):

<code>第一行
第二行</code>
Copy after login
Copy after login
Copy after login
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!