Function putc () in C
The function int putc (int char, FILE * stream) in Library C writes one character (an unsigned char) defined by the parameter char to the given Stream and increases the position indicator for that Stream.
The function int putc (int char, FILE * stream) in Library C writes one character (an unsigned char) defined by the parameter char to the given Stream and increases the position indicator for that Stream.
Declare putc () function in C
Below is the declaration for the putc () function in C:
int putc ( 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 character is written.
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 the putc () function in C:
#include int main () { FILE * fp ; int ch ; fp = fopen ( "baitapc.txt" , "w" ); for ( ch = 33 ; ch <= 100 ; ch ++ ) { putc ( ch , fp ); } fclose ( fp ); return ( 0 ); }
Compiling and running the above program will create a baitc.t.txt in the current directory and have the following content:
Now monitor the above file contents 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 C program will result:
According to Tutorialspoint
Previous article: getchar () function in C
Next lesson: putchar () function in C
- DAY function in SQL Server
- MIN function in SQL Server
- MAX function in SQL Server
- SUM function in SQL Server
- The ord () function in Python
- RIGHT function in SQL Server
- Int () function in Python
- AVG function in SQL Server
- 6 Conditional Functions That Make Excel Spreadsheets Smarter
- Hex () function in Python
- ABS function in SQL Server
- SUM for Newbies Only: Excel Experts Use This Function Instead!
- The function id () in Python
- DATEPART function in SQL Server