C examples for stdio.h:fputc
function
<cstdio> <stdio.h>
Write character to stream
int fputc ( int character, FILE * stream );
Parameter | Description |
---|---|
character | The character to be written. |
stream | a FILE object. |
On success, the character written is returned.
If a writing error occurs, EOF is returned and the error indicator (ferror) is set.
The following code creates a file called data.txt and writes ABCDEFGHIJKLMNOPQRSTUVWXYZ to it.
#include <stdio.h> int main ()//from www .jav a 2 s.c o m { FILE * pFile; char c; pFile = fopen ("data.txt","w"); if (pFile!=NULL) { for (c = 'A' ; c <= 'Z' ; c++) fputc ( c , pFile ); fclose (pFile); } return 0; }