| 1 |
'\" t |
| 2 |
.\" Copyright 1993, Thomas Koenig <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH puts 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
fputc, fputs, putc, putchar, puts \- output of characters and strings |
| 10 |
.SH LIBRARY |
| 11 |
Standard C library |
| 12 |
.RI ( libc ,\~ \-lc ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <stdio.h> |
| 16 |
.P |
| 17 |
.BI "int fputc(int " c ", FILE *" stream ); |
| 18 |
.BI "int putc(int " c ", FILE *" stream ); |
| 19 |
.BI "int putchar(int " c ); |
| 20 |
.P |
| 21 |
.BI "int fputs(const char *restrict " s ", FILE *restrict " stream ); |
| 22 |
.BI "int puts(const char *" s ); |
| 23 |
.fi |
| 24 |
.SH DESCRIPTION |
| 25 |
.BR fputc () |
| 26 |
writes the character |
| 27 |
.IR c , |
| 28 |
cast to an |
| 29 |
.IR "unsigned char" , |
| 30 |
to |
| 31 |
.IR stream . |
| 32 |
.P |
| 33 |
.BR putc () |
| 34 |
is equivalent to |
| 35 |
.BR fputc () |
| 36 |
except that it may be implemented as a macro which evaluates |
| 37 |
.I stream |
| 38 |
more than once. |
| 39 |
.P |
| 40 |
.I putchar(c) |
| 41 |
is equivalent to |
| 42 |
.IR "putc(c,\ stdout)" . |
| 43 |
.P |
| 44 |
.BR fputs () |
| 45 |
writes the string |
| 46 |
.I s |
| 47 |
to |
| 48 |
.IR stream , |
| 49 |
without its terminating null byte (\[aq]\[rs]0\[aq]). |
| 50 |
.P |
| 51 |
.BR puts () |
| 52 |
writes the string |
| 53 |
.I s |
| 54 |
and a trailing newline |
| 55 |
to |
| 56 |
.IR stdout . |
| 57 |
.P |
| 58 |
Calls to the functions described here can be mixed with each other and with |
| 59 |
calls to other output functions from the |
| 60 |
.I stdio |
| 61 |
library for the same output stream. |
| 62 |
.P |
| 63 |
For nonlocking counterparts, see |
| 64 |
.BR unlocked_stdio (3). |
| 65 |
.SH RETURN VALUE |
| 66 |
.BR fputc (), |
| 67 |
.BR putc (), |
| 68 |
and |
| 69 |
.BR putchar () |
| 70 |
return the character written as an |
| 71 |
.I unsigned char |
| 72 |
cast to an |
| 73 |
.I int |
| 74 |
or |
| 75 |
.B EOF |
| 76 |
on error. |
| 77 |
.P |
| 78 |
.BR puts () |
| 79 |
and |
| 80 |
.BR fputs () |
| 81 |
return a nonnegative number on success, or |
| 82 |
.B EOF |
| 83 |
on error. |
| 84 |
.SH ATTRIBUTES |
| 85 |
For an explanation of the terms used in this section, see |
| 86 |
.BR attributes (7). |
| 87 |
.TS |
| 88 |
allbox; |
| 89 |
lbx lb lb |
| 90 |
l l l. |
| 91 |
Interface Attribute Value |
| 92 |
T{ |
| 93 |
.na |
| 94 |
.nh |
| 95 |
.BR fputc (), |
| 96 |
.BR fputs (), |
| 97 |
.BR putc (), |
| 98 |
.BR putchar (), |
| 99 |
.BR puts () |
| 100 |
T} Thread safety MT-Safe |
| 101 |
.TE |
| 102 |
.SH STANDARDS |
| 103 |
C11, POSIX.1-2008. |
| 104 |
.SH HISTORY |
| 105 |
POSIX.1-2001, C89, C99. |
| 106 |
.SH BUGS |
| 107 |
It is not advisable to mix calls to output functions from the |
| 108 |
.I stdio |
| 109 |
library with low-level calls to |
| 110 |
.BR write (2) |
| 111 |
for the file descriptor associated with the same output stream; |
| 112 |
the results will be undefined |
| 113 |
and very probably not what you want. |
| 114 |
.SH SEE ALSO |
| 115 |
.BR write (2), |
| 116 |
.BR ferror (3), |
| 117 |
.BR fgets (3), |
| 118 |
.BR fopen (3), |
| 119 |
.BR fputwc (3), |
| 120 |
.BR fputws (3), |
| 121 |
.BR fseek (3), |
| 122 |
.BR fwrite (3), |
| 123 |
.BR putwchar (3), |
| 124 |
.BR scanf (3), |
| 125 |
.BR unlocked_stdio (3) |