Chapter Contents |
Previous |
Next |
fputc |
Portability: | ISO/ANSI C conforming, UNIX compatible |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
IMPLEMENTATION | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <stdio.h> int fputc(int c, FILE *f);
DESCRIPTION |
fputc
writes a single character
c
to the stream
associated with the
FILE
object addressed
by
f
.
RETURN VALUE |
fputc
returns the character written or
EOF
if
an error occurs.
IMPLEMENTATION |
fputc
is implemented as an actual function call, not a built-in function, so it
is slower than
putc
. (However, less code
is generated.)
EXAMPLE |
#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); }
RELATED FUNCTIONS |
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.