1.NAME
fgetc, fgets, getc, getchar, gets, ungetc - input of characters and
strings
SYNOPSIS
#include
int fgetc(FILE *stream);
char *fgets(char *s, int size, FILE *stream);
int getc(FILE *stream);
int getchar(void);
char *gets(char *s);
int ungetc(int c, FILE *stream);
DESCRIPTION
fgetc() reads the next character from stream and returns it as an
unsigned char cast to an int, or EOF on end of file or error.
getc() is equivalent to fgetc() except that it may be implemented as a
macro which evaluates stream more than once.
getchar() is equivalent to getc(stdin).
gets() reads a line from stdin into the buffer pointed to by s until
either a terminating newline or EOF, which it replaces with '\0'. No
check for buffer overrun is performed (see BUGS below).
fgets() reads in at most one less than size characters from stream and
stores them into the buffer pointed to by s. Reading stops after an
EOF or a newline. If a newline is read, it is stored into the buffer.
A '\0' is stored after the last character in the buffer.
ungetc() pushes c back to stream, cast to unsigned char, where it is
available for subsequent read operations. Pushed-back characters will
be returned in reverse order; only one pushback is guaranteed.
RETURN VALUE
fgetc(), getc() and getchar() return the character read as an unsigned
char cast to an int or EOF on end of file or error.
gets() and fgets() return s on success, and NULL on error or when end
of file occurs while no characters have been read.
ungetc() returns c on success, or EOF on error.
2.NAME
fputc, fputs, putc, putchar, puts - output of characters and strings
SYNOPSIS
#include
int fputc(int c, FILE *stream);
int fputs(const char *s, FILE *stream);
int putc(int c, FILE *stream);
int putchar(int c);
int puts(const char *s);
DESCRIPTION
fputc() writes the character c, cast to an unsigned char, to stream.
fputs() writes the string s to stream, without its trailing '\0'.
putc() is equivalent to fputc() except that it may be implemented as a
macro which evaluates stream more than once.
putchar(c); is equivalent to putc(c,stdout).
puts() writes the string s and a trailing newline to stdout.
RETURN VALUE
fputc(), putc() and putchar() return the character written as an
unsigned char cast to an int or EOF on error.
puts() and fputs() return a nonnegative number on success, or EOF on
error.
3.NAME
clearerr, feof, ferror, fileno - check and reset stream status
SYNOPSIS
#include
void clearerr(FILE *stream);
int feof(FILE *stream);
int ferror(FILE *stream);
int fileno(FILE *stream);
DESCRIPTION
The function clearerr() clears the end-of-file and error indicators for
the stream pointed to by stream.
The function feof() tests the end-of-file indicator for the stream
pointed to by stream, returning nonzero if it is set. The end-of-file
indicator can only be cleared by the function clearerr().
The function ferror() tests the error indicator for the stream pointed
to by stream, returning nonzero if it is set. The error indicator can
only be reset by the clearerr() function.
The function fileno() examines the argument stream and returns its
integer descriptor.
本程序用标准IO将标准输入复制到标准输出(能复制任一UNIX普通文件)。
程序清单: