Writes a string to a stream.
Standard I/O Library (libc.a)
#include <stdio.h>
int puts ( String)
const char *String;
int fputs (String, Stream)
const char *String;
FILE *Stream;
The puts subroutine writes the string pointed to by the String parameter to the standard output stream, stdout, and appends a new-line character to the output.
The fputs subroutine writes the null-terminated string pointed to by the String parameter to the output stream specified by the Stream parameter. The fputs subroutine does not append a new-line character.
Neither subroutine writes the terminating null character.
After the fputwc, putwc, fputc, fputs, puts, or putw subroutine runs successfully, and before the next successful completion of a call either to the fflush or fclose subroutine on the same stream or a call to the exit or abort subroutine, the st_ctime and st_mtime fields of the file are marked for update.
String | Points to a string to be written to output. |
Stream | Points to the FILE structure of an open file. |
Upon successful completion, the puts and fputs subroutines return the number of characters written. Otherwise, both subroutines return EOF, set an error indicator for the stream and set the errno global variable to indicate the error. This happens if the routines try to write to a file that has not been opened for writing.
If the puts or fputs subroutine is unsuccessful because the output stream specified by the Stream parameter is unbuffered or the buffer needs to be flushed, it returns one or more of the following error codes:
EAGAIN | Indicates that the O_NONBLOCK flag is set for the file descriptor specified by the Stream parameter and the process would be delayed in the write operation. |
EBADF | Indicates that the file descriptor specified by the Stream parameter is not a valid file descriptor open for writing. |
EFBIG | Indicates that an attempt was made to write to a file that exceeds the process' file size limit or the systemwide maximum file size. |
EINTR | Indicates that the write operation was terminated due to receipt
of a signal and no data was transferred.
Note
Depending upon which
library routine the application binds to, this subroutine may return EINTR. Refer to the signal subroutine regarding the SA_RESTART
bit. |
EIO | Indicates that the process is a member of a background process group attempting to perform a write to its controlling terminal, the TOSTOP flag is set, the process is neither ignoring or blocking the SIGTTOU signal, and the process group of the process has no parent process. |
ENOSPC | Indicates that there was no free space remaining on the device containing the file specified by the Stream parameter. |
EPIPE | Indicates that an attempt is made to write to a pipe or first-in-first-out (FIFO) that is not open for reading by any process. A SIGPIPE signal will also be sent to the process. |
ENOMEM | Indicates that insufficient storage space is available. |
ENXIO | Indicates that a request was made of a nonexistent device, or the request was outside the capabilities of the device. |
The fopen, freopen, or fdopen (fopen, fopen64, freopen, freopen64 or fdopen Subroutine) subroutine, fread, or fwrite (fread or fwrite Subroutine) subroutine, gets or fgets (gets or fgets Subroutine) subroutine, getws or fgetws (getws or fgetws Subroutine) subroutine, printf, fprintf, and sprintf (printf, fprintf, sprintf, snprintf, wsprintf, vprintf, vfprintf, vsprintf, or vwsprintf Subroutine) subroutine, putc, putchar, fputc, or putw (putc, putchar, fputc, or putw Subroutine)subroutine, putwc, putwchar, or fputwc (putwc, putwchar, or fputwc Subroutine) subroutine, putws or fputws (putws or fputws Subroutine) subroutine.
The feof, ferror, clearerr, or fileno (feof, ferror, clearerr, or fileno Macro) macros.
List of String Manipulation Services.
Subroutines Overview in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.