C language fgets function and fputs function usage

Source: Internet
Author: User

Fgets (buf, size, FP)
It acts in the following manner:
(1) returns when a newline or file end EOF is encountered.
(2) Read by row.
(3) The newline character '/n ' at the end of each line is also the line character.
(4) for buf sizes of size, read only size-1 characters.
(5) automatically fills 0 terminator ('/0 ') after the last character in the buf (usually a newline character).

So if you want to get rid of line breaks in buf, you can do this: Buf[strlen (BUF)-1] = '/0 '; The current premise is that the BUF is large enough to hold the complete line (including the last line break).

Fputs (str, FP)
(1) Enter all the text before the 0 Terminator in Str into the file.
(2) After the completion of the input, no additional special characters, such as line breaks, are added.

If you want to enter the line after STR, you should then call FPUTC (' n ', FP) after the above call;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.