Clear, practical technology insights About · Contact

Function Fgetc ()() in C

Explore Function Fgetc ()() in C with clear explanations, practical examples, and useful tips.

Published: 3 minutes read
Table of Contents

This guide covers function fgetc ()() in c with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.

Declare Function Fgetc ()() in C

Below is the declaration for fgetc () in C:

 int fgetc ( FILE * stream ) 

Parameters

Stream - This is the pointer to a FILE object that identifies Stream on which the operation is performed.

Returns the value

This function returns the character read as an unsigned char that is cast to an int or EOF or an error.

For example

The following program C illustrates the usage of fgetc () in C:

 #include int main () { FILE * fp ; int c ; int n = 0 ; fp = fopen ( "baitapc.txt" , "r" ); if ( fp == NULL ) { perror ( "Xay ra loi khi mo baitapc.txt !!!" ); return (- 1 ); } do { c = fgetc ( fp ); if ( feof ( fp ) ) { break ; } printf ( "%c" , c ); } while ( 1 ); fclose ( fp ); return ( 0 ); } 

Suppose we have baitapc. Txt with the following content. This file will be used as input for C program for example:

Compiling and running the above C program will result:

According to Tutorialspoint

Previous lesson: The function sscanf () in C

Next lesson: Function fgets () in C

Frequently Asked Questions

What should I check before following these steps?

Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.

Why might the process not work?

Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.

Can I undo the changes if necessary?

That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.

Was this article helpful?

Your feedback helps us improve.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.