This section describes functions for performing character- and line-oriented output.
These narrow streams functions are declared in the header file stdio.h and the wide stream functions in wchar.h.
Preliminary: | MT-Safe | AS-Unsafe corrupt | AC-Unsafe corrupt lock | See POSIX Safety Concepts.
The
fputc
function converts the character c to typeunsigned char
, and writes it to the stream stream.EOF
is returned if a write error occurs; otherwise the character c is returned.
Preliminary: | MT-Safe | AS-Unsafe corrupt | AC-Unsafe corrupt lock | See POSIX Safety Concepts.
The
fputwc
function writes the wide character wc to the stream stream.WEOF
is returned if a write error occurs; otherwise the character wc is returned.
Preliminary: | MT-Safe race:stream | AS-Unsafe corrupt | AC-Unsafe corrupt | See POSIX Safety Concepts.
The
fputc_unlocked
function is equivalent to thefputc
function except that it does not implicitly lock the stream.
Preliminary: | MT-Safe race:stream | AS-Unsafe corrupt | AC-Unsafe corrupt | See POSIX Safety Concepts.
The
fputwc_unlocked
function is equivalent to thefputwc
function except that it does not implicitly lock the stream.This function is a GNU extension.
Preliminary: | MT-Safe | AS-Unsafe corrupt | AC-Unsafe corrupt lock | See POSIX Safety Concepts.
This is just like
fputc
, except that most systems implement it as a macro, making it faster. One consequence is that it may evaluate the stream argument more than once, which is an exception to the general rule for macros.putc
is usually the best function to use for writing a single character.
Preliminary: | MT-Safe | AS-Unsafe corrupt | AC-Unsafe corrupt lock | See POSIX Safety Concepts.
This is just like
fputwc
, except that it can be implement as a macro, making it faster. One consequence is that it may evaluate the stream argument more than once, which is an exception to the general rule for macros.putwc
is usually the best function to use for writing a single wide character.
Preliminary: | MT-Safe race:stream | AS-Unsafe corrupt | AC-Unsafe corrupt | See POSIX Safety Concepts.
The
putc_unlocked
function is equivalent to theputc
function except that it does not implicitly lock the stream.
Preliminary: | MT-Safe race:stream | AS-Unsafe corrupt | AC-Unsafe corrupt | See POSIX Safety Concepts.
The
putwc_unlocked
function is equivalent to theputwc
function except that it does not implicitly lock the stream.This function is a GNU extension.
Preliminary: | MT-Safe | AS-Unsafe corrupt | AC-Unsafe corrupt lock | See POSIX Safety Concepts.
The
putchar
function is equivalent toputc
withstdout
as the value of the stream argument.
Preliminary: | MT-Safe | AS-Unsafe corrupt | AC-Unsafe corrupt lock | See POSIX Safety Concepts.
The
putwchar
function is equivalent toputwc
withstdout
as the value of the stream argument.
Preliminary: | MT-Unsafe race:stdout | AS-Unsafe corrupt | AC-Unsafe corrupt | See POSIX Safety Concepts.
The
putchar_unlocked
function is equivalent to theputchar
function except that it does not implicitly lock the stream.
Preliminary: | MT-Unsafe race:stdout | AS-Unsafe corrupt | AC-Unsafe corrupt | See POSIX Safety Concepts.
The
putwchar_unlocked
function is equivalent to theputwchar
function except that it does not implicitly lock the stream.This function is a GNU extension.
Preliminary: | MT-Safe | AS-Unsafe corrupt | AC-Unsafe corrupt lock | See POSIX Safety Concepts.
The function
fputs
writes the string s to the stream stream. The terminating null character is not written. This function does not add a newline character, either. It outputs only the characters in the string.This function returns
EOF
if a write error occurs, and otherwise a non-negative value.For example:
fputs ("Are ", stdout); fputs ("you ", stdout); fputs ("hungry?\n", stdout);outputs the text ‘Are you hungry?’ followed by a newline.
Preliminary: | MT-Safe | AS-Unsafe corrupt | AC-Unsafe corrupt lock | See POSIX Safety Concepts.
The function
fputws
writes the wide character string ws to the stream stream. The terminating null character is not written. This function does not add a newline character, either. It outputs only the characters in the string.This function returns
WEOF
if a write error occurs, and otherwise a non-negative value.
Preliminary: | MT-Safe race:stream | AS-Unsafe corrupt | AC-Unsafe corrupt | See POSIX Safety Concepts.
The
fputs_unlocked
function is equivalent to thefputs
function except that it does not implicitly lock the stream.This function is a GNU extension.
Preliminary: | MT-Safe race:stream | AS-Unsafe corrupt | AC-Unsafe corrupt | See POSIX Safety Concepts.
The
fputws_unlocked
function is equivalent to thefputws
function except that it does not implicitly lock the stream.This function is a GNU extension.
Preliminary: | MT-Safe | AS-Unsafe corrupt | AC-Unsafe lock corrupt | See POSIX Safety Concepts.
The
puts
function writes the string s to the streamstdout
followed by a newline. The terminating null character of the string is not written. (Note thatfputs
does not write a newline as this function does.)
puts
is the most convenient function for printing simple messages. For example:puts ("This is a message.");outputs the text ‘This is a message.’ followed by a newline.
Preliminary: | MT-Safe | AS-Unsafe corrupt | AC-Unsafe lock corrupt | See POSIX Safety Concepts.
This function writes the word w (that is, an
int
) to stream. It is provided for compatibility with SVID, but we recommend you usefwrite
instead (see Block Input/Output).