#include <stdio.h> int fputc(int c, FILE *f);
fputc
writes a single character c
to the stream associated with
the FILE
object addressed by f
.
fputc
returns the character written or EOF
if an error occurs.
fputc
is implemented as an actual function call, not a built-in function,
so it is slower than putc
. (However, less code is generated.)
#include <stdio.h> #include <string.h> #include <stdlib.h> main() { int c; /* must be int not char */ char filename[60]; FILE *infile, *outfile; puts("Enter the name of your input file:"); memcpy(filename, "tso:", 4); gets(filename+4); infile = fopen(filename, "r"); if (!infile){ puts("Failed to open input file."); exit(EXIT_FAILURE); } puts("Enter the name of your output file:"); memcpy(filename, "tso:", 4); gets(filename+4); outfile = fopen(filename, "w"); if (!outfile){ puts("Failed to open output file."); exit(EXIT_FAILURE); } /* Read characters from file MYFILE. */ while ((c = fgetc(infile)) != EOF) /* Write characters to YOURFILE. */ if (fputc(c, outfile) == EOF) break; fclose(infile); }
putc
, putchar
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.