.TH fputc() "" "" "STDIO Function (libc)"
.PC "Write character into file stream"
.B "#include <stdio.h>"
\fBint fputc(\fIc\fB, \fIfp\^\fB)
char \fIc\fB; FILE *\fIfp\fB;\fR
.PP
.B fputc()
writes the character
.I c
into the file stream pointed to by
.IR fp .
It returns
.I c
if
.I c
was written successfully.
.SH Example
The following example uses \fBfputc\fR to write the contents of one
file into another.
.DM
#include <stdio.h>
.DE
.DM
void fatal(message)
char *message;
{
	fprintf(stderr, "%s\en", message);
	exit(1);
}
.DE
.DM
main()
{
	FILE *fp, *fout;
	int ch;
	int infile[20];
	int outfile[20];
.DE
.DM
	printf("Enter name to copy: ");
	gets(infile);
	printf("Enter name of new file: ");
	gets(outfile);
.DE
.DM
	if ((fp = fopen(infile, "r")) == NULL)
		fatal("Cannot write input file");
.DE
.DM
	if ((fout = fopen(outfile, "w")) != NULL) 
		fatal("Cannot write output file");
.DE
.DM
	while ((ch = fgetc(fp)) != EOF) 
		fputc(ch, fout);
}
.DE
.SH "See Also"
.Xr "libc" libc
.br
\*(AS, \(sc7.9.7.3
.br
\*(PX Standard, \(sc8.1
.SH Diagnostics
.B fputc()
returns EOF when a write error occurs, e.g., when a disk runs out of space.
