Write a character to a stream.
Compatibility:This function is compatible with the following targets:
|
|
#include <stdio.h>
int putc(int c, FILE *stream);Parameters:
Parameters for this facility are:
The putc() function outputs c to stream and advances stream's file position indicator.
The putc() works identically to the fputc() function, except that it is written as a macro.
putc() returns the character written when successful and return EOF when it fails.
"Wide Character and Byte Character Stream Orientation"
Example of putc() usage.:#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *f;
static char filename[] = "checkputc";
static char test[] = "flying fish and quail eggs";
int i;
// create a new file for output
if (( f = fopen(filename, "w")) == NULL) {
printf("Can't open %s.\n", filename);
exit(1);
}
// output the test character array
// one character at a time using putc()
for (i = 0; test[i] > 0; i++)
putc(test[i], f);
// close the file
fclose(f);
return 0;
}