# fgetc

## NAME



           fgetc, fgets, getc, getchar, ungetc - input of characters and
           strings
    


## LIBRARY



           Standard C library (_libc_ , _-lc_)
    


## SYNOPSIS



           **#include <stdio.h>**
    
           **int fgetc(FILE ***_stream_**);**
           **int getc(FILE ***_stream_**);**
           **int getchar(void);**
    
           **char *fgets(** int size;
                       **char** _s_**[restrict** _size_**], int** _size_**, FILE *restrict** _stream_**);**
    
           **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)_.
    
           **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 terminating null byte ('\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.
    
           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 nonlocking 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.
    
           **fgets**() returns _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.
    


## ATTRIBUTES



           For an explanation of the terms used in this section, see
           attributes(7).
           ┌──────────────────────────────────────┬───────────────┬─────────┐
           │ **Interface** │ **Attribute** │ **Value** │
           ├──────────────────────────────────────┼───────────────┼─────────┤
           │ **fgetc**(), **fgets**(), **getc**(), **getchar**(), │ Thread safety │ MT-Safe │
           │ **ungetc**()                             │               │         │
           └──────────────────────────────────────┴───────────────┴─────────┘
    


## STANDARDS



           C11, POSIX.1-2008.
    


## NOTES



           It is not advisable to mix calls to input functions from the _stdio_
           library with low-level calls to read(2) for the file descriptor
           associated with the input stream; the results will be undefined
           and very probably not what you want.
    


* * *