Names specified here
Name Description Notes Source Availability
fgetc() Input character (·) <stdio.h> C89 C90 C95 C99 C11
fgetwc() Input wide character (·) <wchar.h> C95 C99 C11
getc() Input character (·) <stdio.h> C89 C90 C95 C99 C11
getchar() Input character from standard input (·) <stdio.h> C89 C90 C95 C99 C11
getwc() Input wide character (·) <wchar.h> C95 C99 C11
getwchar() Input wide character from standard input (·) <wchar.h> C95 C99 C11
ungetc() Replace character (·) <stdio.h> C89 C90 C95 C99 C11
ungetwc() Replace character (·) <wchar.h> C95 C99 C11
#include <stdio.h>
int getc(FILE *fp);
int fgetc(FILE *fp);
int getchar(void);
int ungetc(int c, FILE *fp);

#include <wchar.h>
wint_t getwc(FILE *fp);
wint_t fgetwc(FILE *fp);
wint_t ungetwc(wchar_t c, FILE *fp);
#include <wchar.h>
wint_t getwchar(void);

Do not use ungetc on a binary stream with zero position. The definedness of this behaviour is obsolescent.

getc and fgetc each read a single byte from the input stream fp. It is converted to unsigned char, and then returned as int. If the stream was already at its end, the functions set the end-of-file indicator, and return EOF.

Similarly, getwc and fgetwc each read a single wide character from the input stream fp. It is converted to wint_t and returned. If the stream was already at its end, the functions set the end-of-file indicator, and return WEOF.

If getc or getwc is a macro, it might evaluate its argument more than once, so don't use expressions with side effects as arguments to these functions. fgetc and fgetwc are guaranteed not to do this.

getchar() is equivalent to getc(stdin). getwchar() is equivalent to getwc(stdin).

ungetc and ungetwc push the byte or character c back onto the input stream fp so that it will be read as the next byte or character. At most one byte or character is guaranteed to be able to be pushed back before being read again. To push back a char, convert it to unsigned char before passing it to ungetc, e.g., ungetc((unsigned char) c, stdin). ungetc returns c on success, and EOF on error. ungetwc returns WEOF if c is WEOF or an invalid wide character.

The functions getc, fgetc, getchar and ungetc are byte-oriented. The functions getwc, fgetwc, getwchar and ungetwc are wide-oriented.


CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2023-10-04T20:24:03.205+0000