cplusplus.com > reference > cstdio > putc |
putc
<stdio.h> |
cplusplus.com |
Write character to stream.
Writes character to the current position in the specified stream
and increase the file pointer to point to next character.
This routine is normally implemented as a macro with the same result as fputc.
Parameters.
Return Value.
If there are no errors the written character is returned.
If an error occurs, EOF is returned.
Portability.
Defined in ANSI-C. Compatible with K&R.
Example.
/* putc example: alphabet writer */
#include <stdio.h>
int main ()
{
FILE * pFile;
char c;
pFile=fopen("alphabet.txt","wt")
for (c = 'A' ; c <= 'Z' ; c++) {
putc (n , pFile);
}
fclose (pFile);
return 0;
}
This program creates a file called alphabet.txt and writes
ABCDEFGHIJKLMNOPQRSTUVWXYZ on it.
See also.
fgetc,
fputc,
fwrite,
getchar,
putchar