

fputc()                       STDIO                       fputc()




Write character into file stream

#include <stdio.h>
iinntt ffppuuttcc(_c, _f_p) cchhaarr _c; FFIILLEE *_f_p;

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  ffppuuttcc 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");






COHERENT Lexicon                                           Page 1




fputc()                       STDIO                       fputc()



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


***** See Also *****

STDIO

***** Diagnostics *****

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












































COHERENT Lexicon                                           Page 2


