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 anunsigned char, to stream. that "cast to unsigned char" part is lowkey important, don't skip it bestie.putc()is equivalent tofputc()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 toputc(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 tostdout. 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(), andputchar()return the character written, as anunsigned charcast to anint, orEOFon error.puts()andfputs()return a nonnegative number on success, orEOFon 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
- 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