<cstdio>
int fputc ( int character, FILE * stream );
Write character to stream
Writes a character to the stream and advances the position indicator.
The character is written at the current position of the stream as indicated by the internal position indicator, which is then advanced one character.
Parameters
- character
- Character to be written. The character is passed as its int promotion.
- stream
- Pointer to a FILE object that identifies the stream where the character is to be written.
Return Value
If there are no errors, the same character that has been written is returned.
If an error occurs, EOF is returned and the error indicator is set (see ferror).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
/* 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 ( (int) c , pFile );
}
fclose (pFile);
}
return 0;
}
|
This program creates a file called alphabet.txt and writes ABCDEFGHIJKLMNOPQRSTUVWXYZ to it.
See also
putc | Write character to stream (function) |
fgetc | Get character from stream (function) |
fwrite | Write block of data to stream (function) |
fopen | Open file (function) |
|