COHERENT manpages

This page displays the COHERENT manpage for fputc() [Write character into file stream].

List of available manpages
Index


fputc() -- STDIO Function (libc)

Write character into file stream
#include <stdio.h>
int fputc(c, fp)
char c; FILE *fp;

fputc() writes  the character c into  the file stream pointed  to by fp. It
returns c if c was written successfully.

Example

The following  example uses fputc  to write the  contents of one  file into
another.

#include <stdio.h>

void fatal(message)
char *message;
{
    fprintf(stderr, "%s\n", message);
    exit(1);
}

main()
{
    FILE *fp, *fout;
    int ch;
    int infile[20];
    int outfile[20];

    printf("Enter name to copy: ");
    gets(infile);
    printf("Enter name of new file: ");
    gets(outfile);

    if ((fp = fopen(infile, "r")) == NULL)
        fatal("Cannot write input file");

    if ((fout = fopen(outfile, "w")) != NULL)
        fatal("Cannot write output file");

    while ((ch = fgetc(fp)) != EOF)
        fputc(ch, fout);
}

See Also

libc
ANSI Standard, §7.9.7.3
POSIX Standard, §8.1

Diagnostics

fputc() returns EOF  when a write error occurs, e.g.,  when a disk runs out
of space.