Fgets and fputs Functions

Source: Internet
Author: User

1 function input

The following two functions provide the function of inputting a row at a time.

# Include <stdio. h> char * fgets (char * restrict Buf, int N, file * restrict FP); char * gets (char * BUF); two function return values: If successful, the return value is Buf, if the end of the file is reached or an error occurs, null is returned.

Both functions specify the buffer address, and the row to be read is sent to it. Gets reads from the standard input, while fgets reads from the specified stream.

 

2 function output

Provides the ability to output a row at a time.

# Include <stdio. h> int fputs (const char * restrict STR, file * restrict FP); int puts (const char * Str); two function return values: If successful, non-negative values are returned, if an error occurs, EOF is returned.

 

 

Example:

# Include <stdio. h>
# Define N 9
Char Buf [N];
Int main ()
{
Int I;
If (fgets (BUF, N, stdin )! = NULL)
Printf ("fgets success \ n ");
Else printf ("fgets error \ n ");
I = fputs (BUF, stdout );
If (I> 0) printf ("\ n fputs success \ n ");
Else printf ("\ n fputs error \ n ");

Return 0;
}

Fgets and fputs Functions

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.