Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

fgetc(2) [plan9 man page]

FGETC(2)							System Calls Manual							  FGETC(2)

NAME
fgetc, getc, getchar, fputc, putc, putchar, ungetc, fgets, gets, fputs, puts, fread, fwrite - Stdio input and output SYNOPSIS
#include <stdio.h> int fgetc(FILE *f) int getc(FILE *f) int getchar(void) int fputc(int c, FILE *f) int putc(int c, FILE *f) int putchar(int c) int ungetc(int c, FILE *f) char *fgets(char *s, int n, FILE *f) char *gets(char *s) int fputs(char *s, FILE *f) int puts(char *s) long fread(void *ptr, long itemsize, long nitems, FILE *stream) long fwrite(void *ptr, long itemsize, long nitems, FILE *stream) DESCRIPTION
The functions described here work on open Stdio streams (see fopen). Fgetc returns as an int the next unsigned char from input stream f. If the stream is at end-of-file, the end-of-file indicator for the stream is set and fgetc returns EOF. If a read error occurs, the error indicator for the stream is set and fgetc returns EOF. Getc is like fgetc except that it is implemented as a macro. Getchar is like getc except that it always reads from stdin. Ungetc pushes character c back onto the input stream f. The pushed-back character will be returned by subsequent reads in the reverse order of their pushing. A successful intervening fseek, fsetpos, or rewind on f discards any pushed-back characters for f. One character of push-back is guaranteed. Ungetc returns the character pushed back (converted to unsigned char), or EOF if the operation fails. A suc- cessful call to ungetc clears the end-of-file indicator for the stream. The file position indicator for the stream after reading or dis- carding all pushed-back characters is the same as it was before the characters were pushed back. Fputc writes character c (converted to unsigned char) to output stream f at the position indicated by the position indicator for the stream and advances the indicator appropriately. If the file cannot support positioning requests, or if the stream was opened with append mode, the character is appended to the output stream. Fputc returns the character written or EOF if there was a write error. Putc is like fputc but is implemented as a macro. Putchar is like putc except that it always writes to stdout. All other input takes place as if characters were read by successive calls to fgetc and all other output takes place as if characters were written by successive calls to fputc. Fgets reads up to and including the next newline, but not past end-of-file or more than n-1 characters, from stream f into array s. A null character is written immediately after the last character read into the array (if any characters are read at all). Fgets returns s if suc- cessful, otherwise a null pointer. Gets is similar to fgets except that it always reads from stdin and it discards the terminating new- line, if any. Gets does not check for overflow of the receiving array, so its use is deprecated. Fputs writes the string s to stream f, returning EOF if a write error occurred, otherwise a nonnegative value. The terminating null char- acter is not written. Puts is the same, writing to stdout. Fread reads from the named input stream at most nitems of data of size itemsize and the type of *ptr into a block beginning at ptr. It returns the number of items actually read. Fwrite appends to the named output stream at most nitems of data of size itemsize and the type of *ptr from a block beginning at ptr. It returns the number of items actually written. SOURCE
/sys/src/libstdio SEE ALSO
read(2), fopen(2), bio(2) BUGS
Stdio does not handle UTF or runes; use Bio instead. FGETC(2)

Check Out this Related Man Page

GETS(3) 						     Linux Programmer's Manual							   GETS(3)

NAME
fgetc, fgets, getc, getchar, gets, ungetc - input of characters and strings SYNOPSIS
#include <stdio.h> 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 ''. 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 '' 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. Calls to the functions described here can be mixed with each other and with calls to other input functions from the stdio library for the same input stream. For non-locking counterparts, see unlocked_stdio(3). 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. CONFORMING TO
ANSI - C, POSIX.1 BUGS
Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead. It is not advisable to mix calls to input functions from the stdio library with low - level calls to read() for the file descriptor associ- ated with the input stream; the results will be undefined and very probably not what you want. SEE ALSO
read(2), write(2), ferror(3), fopen(3), fread(3), fseek(3), puts(3), scanf(3), unlocked_stdio(3) GNU
1993-04-04 GETS(3)
Man Page