putc() - I/O Function

How is "putc()" used in C++?


putc() is an I/O function which is equivalent to fputc(). putc is used to write the character to the specified stream at the current file position indicator, then increases file position indicator. If no error occurs the same character that has been written is returned otherwise EOF is returned with the error indicator being set.


int putc ( int character, FILE * stream );

Example :

#include <stdio.h>
int main()
char c;
FILE * str= fopen("text.txt","wt");
for (c = 'A' ; c <= 'C' ; c++)
putc (c , str);
fclose (str);
return 0;



In the above example the "putc()" is used to write a character "ABC" to the specified stream into a text file.

C++ Tutorial

Ask Questions

Ask Question