GETCHAR(3P)

✨ GETCHAR(3P) ✨

okay bestie, gather round, because we're doing getchar from the POSIX Programmer's Manual and she is, lowkey, the simplest icon in the whole stdio friend group πŸ’–

🌸 PROLOG 🌸

okay so before literally anything else: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β€” so if you're on Linux, go consult the corresponding Linux manual page for the deets on Linux behavior. Orrrr the interface might just straight up not be implemented on Linux at all. πŸ™ˆ vibe check your platform first, fr fr.


πŸ‘‘ NAME πŸ‘‘

getchar β€” get a byte from a stdin stream


πŸŽ€ SYNOPSIS πŸŽ€

#include <stdio.h>

int getchar(void);

that's it. no args. she takes nothing and gives you a byte. main character energy honestly. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional β€” no drama intended, it's giving "we defer to the ISO C standard, periodt." This volume of POSIX.1‐2017 defers to the ISO C standard.

The getchar() function shall be equivalent to getc(stdin).

that's the whole tea. it's getc(stdin). iconic behavior. ✨


🌈 RETURN VALUE 🌈

Refer to fgetc().


πŸ”₯ ERRORS πŸ”₯

Refer to fgetc().

The following sections are informative.


πŸ“ EXAMPLES πŸ“

None.

(not a single one. she's too simple to need examples and honestly? respect. 😭)


🫢 APPLICATION USAGE 🫢

okay this is the part where I need you to listen, bestie, because this is the classic trap πŸ‘€

If the integer value returned by getchar() is stored into a variable of type char and then compared against the integer constant EOF, the comparison may never succeed, because sign-extension of a variable of type char on widening to integer is implementation-defined.

bestie. bestie please. don't put the getchar() return value in a char. put it in an int. EOF lives in int land and you're trying to match it with a char and it's just not gonna work out. πŸ’€

🧚 RATIONALE 🧚

None.


⭐ FUTURE DIRECTIONS ⭐

None.


πŸ’œ SEE ALSO πŸ’œ

  • Section 2.5, Standard I/O Streams, getc()
  • The Base Definitions volume of POSIX.1‐2017, <stdio.h>

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie!! πŸŽ€ this one came to you from IEEE/The Open Group, 2017 β€” that's the source and the date, right there in the footer, slay πŸ’– now go read fgetc() because apparently that's where all the actual answers live. no cap. bye!! πŸ¦‹βœ¨

πŸ“¦ where this page comes from