Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)
1st Parameter
The character to be written, represented as an `int`. The value is internally converted to `unsigned char`.
2nd Parameter Type : FILE *
Pointer to FILE structure for file operations
2nd Parameter
Pointer to the `FILE` stream where the character is to be written.
Read more about parameters of putc in parameters section
The putcfunction in C language Writes a character to the specified stream.
The putc function writes a single character to the specified output stream at the current position. It is equivalent to fputc() but may be implemented as a macro, which means it may evaluate the stream argument more than once. This function is commonly used for character-by-character output to files or other streams.
The putcfunction takes 2
parameters:
•
int `character`: The character to be written, represented as an `int`. The value is internally converted to `unsigned char`.
•
FILE * `stream`: Pointer to the `FILE` stream where the character is to be written.
Writes the character specified by `character` to the output stream pointed to by `stream`. Returns the character written as an `unsigned char` cast to `int`, or `EOF` if an error occurs. Typically used for character-by-character output.
The putc function return value :
Returns the character written as an unsigned char cast to an int if successful, or EOF if an error occurred
Output
This example demonstrates how to use putc to write a string character by character to a file. It also shows proper error checking.