function
<cstdio>
fputc
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 position indicated by the internal position indicator of the stream, which is then automatically advanced by one.
Parameters
- character
- The int promotion of the character to be written.
The value is internally converted to an unsigned char when written.
- stream
- Pointer to a FILE object that identifies an output stream.
Return Value
On success, the character written is returned.
If a writing error occurs, EOF is returned and the error indicator (ferror) is set.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
/* 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 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
)