puts(3)

๐Ÿ’– puts(3) โ€” the character & string output girlies ๐Ÿ’–

okay so bestie, welcome to puts(3), a lil slice of the Library Functions Manual and honestly? it's giving "i just wanna print some stuff" and we love that for it. this page is the whole girl group: fputc, fputs, putc, putchar, puts. five icons, one stage, no skips. ๐ŸŽ€


๐Ÿ“š LIBRARY

Standard C library โ€” that's libc, aka -lc. she's everywhere, she's been everywhere, periodt. ๐Ÿ’…


โœจ SYNOPSIS โœจ

#include <stdio.h>

int fputc(int c, FILE *stream);
int putc(int c, FILE *stream);
int putchar(int c);

int fputs(const char *restrict s, FILE *restrict stream);
int puts(const char *s);

yes queen, all of them live behind <stdio.h>. include it or you're fighting the compiler for no reason ๐Ÿซถ


๐ŸŒธ DESCRIPTION ๐ŸŒธ

okay so here's what each one actually does, no gatekeeping:

  • fputc() writes the character c, cast to an unsigned char, to stream. that "cast to unsigned char" part is lowkey important, don't skip it bestie.
  • putc() is equivalent to fputc() except that it may be implemented as a macro which evaluates stream more than once. ๐Ÿ˜ญ so likeโ€ฆ if you put something with side effects in there, it could get evaluated multiple times. the way that's a whole trap. be careful.
  • putchar(c) is equivalent to putc(c, stdout). it's the shortcut girlie. cute, simple, no thoughts.
  • fputs() writes the string s to stream, without its terminating null byte ('\0'). the null byte stays home. she's not invited. bye ๐Ÿฆ‹
  • puts() writes the string s and a trailing newline to stdout. yes she adds the newline for you, she's thoughtful like that ๐Ÿ’–

and the best part? calls to the functions described here can be mixed with each other and with calls to other output functions from the stdio library for the same output stream. so they all play nice together, it's a whole collab. โœจ

if you want the nonlocking counterparts, go look at unlocked_stdio(3) โ€” she's in her own lane. ๐Ÿ‘‘


๐Ÿซถ RETURN VALUE ๐Ÿซถ

  • fputc(), putc(), and putchar() return the character written, as an unsigned char cast to an int, or EOF on error.
  • puts() and fputs() return a nonnegative number on success, or EOF on error.

so like, check your return values bestie, EOF means something went wrong and you should probably care about it. ๐Ÿ™ˆ


๐Ÿ’… ATTRIBUTES ๐Ÿ’…

the original had a whole little table here, so let me break it down for you, no cap:

For an explanation of the terms used in this section, see attributes(7).

  • Interface: fputc(), fputs(), putc(), putchar(), puts()
  • Attribute: Thread safety
  • Value: MT-Safe

that's it. all five of them. MT-Safe. every single one. iconic behavior honestly. ๐Ÿ”ฅ


โญ STANDARDS โญ

C11, POSIX.1-2008.


๐ŸŒˆ HISTORY ๐ŸŒˆ

POSIX.1-2001, C89, C99.

she's been around. she's a legacy icon. respect the elders. ๐Ÿ‘‘


๐Ÿ’€ BUGS ๐Ÿ’€

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

likeโ€ฆ not me warning you about buffering chaos. ๐Ÿ˜ญ stdio is doing her own little buffering thing and write(2) is out here raw-dogging the file descriptor, and when those two meet for the same stream?? undefined behavior. it's giving disaster. just don't. pick a lane bestie. ๐Ÿšซ


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

write(2), ferror(3), fgets(3), fopen(3), fputwc(3), fputws(3), fseek(3), fwrite(3), putwchar(3), scanf(3), unlocked_stdio(3)


that's the whole page bestie, you ate it, you understood it, you're literally a C dev now ๐Ÿ’–โœจ

signing off with all the love: this was Linux man-pages 6.20, dated 2026-02-08, and it's all about puts(3). mwah. ๐ŸŽ€๐Ÿฆ‹๐Ÿงš๐Ÿ’œ

๐Ÿ“ฆ 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms