Fgetc and fputc Functions

Source: Internet
Author: User

1. Input Functions

The following three functions can be used to read one character at a time.

# Include <stdio. h> int GETC (File * FP); int fgetc (File * FP); int getchar (void); return values of the three functions: If the function succeeds, the next character is returned, if the end of the file is reached or an error occurs, EOF is returned.

The getchar function is equivalent to GETC (stdin ). The difference between the first two functions is that GETC can be implemented as a macro, while fgetc cannot be implemented as a macro.

2. Output Functions

Each input function described above has an output function.

# Include <stdio. h> int putc (int c, file * FP); int fputc (int c, file * FP); int putchar (int c); return values of the three functions: if the call succeeds, return C. If the call fails, return EOF.

Like the input function, putchar (c) is equivalent to putc (C, staout). putc can be implemented as a macro, while fputc cannot.

 

Example:

# Include <stdio. h>

Int main ()

{
Char C;
Int I;
C = GETC (stdin );
Printf ("input is: \ n ");
I = putc (C, stdout );

If (I) printf ("\ nputc success \ n ");
Else printf ("putc error \ n ");
Return 0;
}

 

Fgetc and fputc 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.