Next: Character Input, Previous: Streams and I18N, Up: I/O on Streams
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.
The
fputcfunction converts the character c to typeunsigned char, and writes it to the stream stream.EOFis returned if a write error occurs; otherwise the character c is returned.
The
fputwcfunction writes the wide character wc to the stream stream.WEOFis returned if a write error occurs; otherwise the character wc is returned.
The
fputc_unlockedfunction is equivalent to thefputcfunction except that it does not implicitly lock the stream.
The
fputwc_unlockedfunction is equivalent to thefputwcfunction except that it does not implicitly lock the stream.This function is a GNU extension.
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.putcis usually the best function to use for writing a single character.
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.putwcis usually the best function to use for writing a single wide character.
The
putc_unlockedfunction is equivalent to theputcfunction except that it does not implicitly lock the stream.
The
putwc_unlockedfunction is equivalent to theputwcfunction except that it does not implicitly lock the stream.This function is a GNU extension.
The
putcharfunction is equivalent toputcwithstdoutas the value of the stream argument.
The
putwcharfunction is equivalent toputwcwithstdoutas the value of the stream argument.
The
putchar_unlockedfunction is equivalent to theputcharfunction except that it does not implicitly lock the stream.
The
putwchar_unlockedfunction is equivalent to theputwcharfunction except that it does not implicitly lock the stream.This function is a GNU extension.
The function
fputswrites 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
EOFif 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.
The function
fputwswrites 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
WEOFif a write error occurs, and otherwise a non-negative value.
The
fputs_unlockedfunction is equivalent to thefputsfunction except that it does not implicitly lock the stream.This function is a GNU extension.
The
fputws_unlockedfunction is equivalent to thefputwsfunction except that it does not implicitly lock the stream.This function is a GNU extension.
The
putsfunction writes the string s to the streamstdoutfollowed by a newline. The terminating null character of the string is not written. (Note thatfputsdoes not write a newline as this function does.)
putsis 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.
This function writes the word w (that is, an
int) to stream. It is provided for compatibility with SVID, but we recommend you usefwriteinstead (see Block Input/Output).