fgetc(3)
โจ fgetc โ the manual, but make it make sense โจ
okay bestie, welcome to the fgetc(3) page ๐ it lives in the Library Functions Manual, and it's literally the origin story of fgetc, getchar, and ungetc โ the trio that reads single characters out of a FILE. yes, one character at a time. no, that's not a crime, it's a vibe. ๐ธ
๐ NAME
fgetc, getchar, ungetc โ grab a character from a FILE, that's the whole job.
๐ LIBRARY
Standard C library, aka libc, link it with -lc. classic. ๐
๐ฆ SYNOPSIS
#include <stdio.h>
int fgetc(FILE *stream);
int getchar(void);
int ungetc(int c, FILE *stream);
like. three little functions. three little icons. periodt. โจ
๐ DESCRIPTION
fgetc() reads the next character out of stream and hands it back to you as an unsigned char cast to an int ๐
or it gives you EOF if you hit end of file or an error happens. that's it, that's the function.
getchar() is literally just fgetc(stdin). same energy, fewer arguments. it's giving "I didn't want to type stdin". ๐
ungetc() pushes c back onto stream, cast to unsigned char, where it waits patiently for the next read operation to come pick it up. so iconic of it. ๐ซถ
โ ๏ธ okay important: pushed-back characters come back in reverse order, and only one pushback is guaranteed. ONE. so don't be out here pushing back a whole paragraph and expecting an orderly queue, bestie, that's not the deal. ๐ญ
calls to these functions can be mixed with each other, and also with calls to other input functions from the stdio library, as long as it's the same input stream. they're chill like that. ๐
for nonlocking counterparts, go look at unlocked_stdio(3). ๐ฅ
๐ RETURN VALUE
fgetc()andgetchar()โ return the character read as anunsigned charcast to anint, orEOFon end of file or error.ungetc()โ returnscon success, orEOFon error.
and if something goes wrong, errno is set to tell you what's up. always check on your friends. โจ
๐ญ ERRORS
see read(2). go read it. it knows things. ๐
๐ง ATTRIBUTES
for an explanation of the terms used in this section, see attributes(7).
- Interface:
fgetc(),getchar(),ungetc()- Attribute: Thread safety
- Value:
MT-Safe
MT-Safe, meaning they're safe to call from multiple threads. slay. ๐
๐ STANDARDS
C11, POSIX.1-2008. it's giving certified. it's giving committee-approved. ๐
๐ฐ๏ธ HISTORY
POSIX.1-2001, C89. ancient. ancestral. the blueprint. ๐ธ
๐ NOTES
๐ do NOT mix calls to input functions from the stdio library with low-level calls to read(2) on the file descriptor associated with the input stream. the results will be undefined, and very probably not what you want. like, not even a little bit what you want. bestie please. just don't. ๐ญ
๐ SEE ALSO
read(2), write(2), ferror(3), fgetwc(3), fgets(3), fopen(3), fread(3), fseek(3), getline(3), gets(3), getwchar(3), puts(3), scanf(3), ungetwc(3), unlocked_stdio(3), feature_test_macros(7)
okay that's the whole page, you ate it, you understood it, you're basically a stdio main character now. ๐๐
this has been Linux man-pages 6.20, dated 2026-08-19, and fgetc(3) โ drink water, close your streams, bye bestie ๐ธ๐ฆโจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, Thomas Koenig <ig25@rz.uni-karlsruhe.de>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms