cplusplus.com > reference > cstdio > fputc |
fputc
<stdio.h> |
cplusplus.com |
Write character to stream.
Writes character to the current position in the specified stream
and increases the file position pointer to the next character.
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.
Example.
/* fputc example: alphabet writer */
#include <stdio.h>
int main ()
{
FILE * pFile;
char c;
pFile = fopen ("alphabet.txt","w");
if (pFile!=NULL)
{
for (c = 'A' ; c <= 'Z' ; c++)
{
fputc (c , pFile);
}
fclose (pFile);
}
return 0;
}
This program creates a file called alphabet.txt and writes
ABCDEFGHIJKLMNOPQRSTUVWXYZ on it.
See also.
fgetc,
fread,
fwrite,
fopen,
putc