Table of Contents
This guide covers function fputc ()() in c with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.
Declare Function Fputc ()() in C
Below is the declaration for fputc () in C:
int fputc ( int char , FILE * stream )
Parameters
Char - This is the character written.
Stream - This is the pointer to a FILE object that identifies the Stream, where the characters are recorded.
Returns the value
If there is no error, the same character will be returned. If an error occurs, the EOF is returned and the Error Indicator is set.
For example
The following program C illustrates the usage of fputc () in C:
#include int main () { FILE * fp ; int ch ; fp = fopen ( "baitapc.txt" , "w+" ); for ( ch = 33 ; ch <= 100 ; ch ++ ) { fputc ( ch , fp ); } fclose ( fp ); return ( 0 ); } Compiling and running the above program will create a baitc. T. Txt in the current directory, and will have the following content:
! "# $% & '() * +, -. / 0123456789:; <=>? @ ABCDEFGHIJKLMNOPQRSTUVWXYZ [] ^ _` abcd
Now follow the contents of the above file by using the following C program:
#include int main () { FILE * fp ; int c ; fp = fopen ( "baitapc.txt" , "r" ); while ( 1 ) { c = fgetc ( fp ); if ( feof ( fp ) ) { break ; } printf ( "%c" , c ); } fclose ( fp ); return ( 0 ); } Compiling and running the above program will result:
According to Tutorialspoint
Previous lesson: Function fgets () in C
Next lesson: Function fputs () 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.
Reader Comments 0
Sign in with email or Google to join the discussion.