1PUTS(3P) POSIX Programmer's Manual PUTS(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 puts — put a string on standard output
14
16 #include <stdio.h>
17
18 int puts(const char *s);
19
21 The functionality described on this reference page is aligned with the
22 ISO C standard. Any conflict between the requirements described here
23 and the ISO C standard is unintentional. This volume of POSIX.1‐2008
24 defers to the ISO C standard.
25
26 The puts() function shall write the string pointed to by s, followed by
27 a <newline>, to the standard output stream stdout. The terminating
28 null byte shall not be written.
29
30 The last data modification and last file status change timestamps of
31 the file shall be marked for update between the successful execution of
32 puts() and the next successful completion of a call to fflush() or
33 fclose() on the same stream or a call to exit() or abort().
34
36 Upon successful completion, puts() shall return a non-negative number.
37 Otherwise, it shall return EOF, shall set an error indicator for the
38 stream, and errno shall be set to indicate the error.
39
41 Refer to fputc().
42
43 The following sections are informative.
44
46 Printing to Standard Output
47 The following example gets the current time, converts it to a string
48 using localtime() and asctime(), and prints it to standard output using
49 puts(). It then prints the number of minutes to an event for which it
50 is waiting.
51
52 #include <time.h>
53 #include <stdio.h>
54 ...
55 time_t now;
56 int minutes_to_event;
57 ...
58 time(&now);
59 printf("The time is ");
60 puts(asctime(localtime(&now)));
61 printf("There are %d minutes to the event.\n",
62 minutes_to_event);
63 ...
64
66 The puts() function appends a <newline>, while fputs() does not.
67
68 This volume of POSIX.1‐2008 requires that successful completion simply
69 return a non-negative integer. There are at least three known different
70 implementation conventions for this requirement:
71
72 * Return a constant value.
73
74 * Return the last character written.
75
76 * Return the number of bytes written. Note that this implementation
77 convention cannot be adhered to for strings longer than {INT_MAX}
78 bytes as the value would not be representable in the return type of
79 the function. For backwards compatibility, implementations can
80 return the number of bytes for strings of up to {INT_MAX} bytes,
81 and return {INT_MAX} for all longer strings.
82
84 None.
85
87 None.
88
90 Section 2.5, Standard I/O Streams, fopen(), fputs(), putc()
91
92 The Base Definitions volume of POSIX.1‐2008, <stdio.h>
93
95 Portions of this text are reprinted and reproduced in electronic form
96 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
97 -- Portable Operating System Interface (POSIX), The Open Group Base
98 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
99 cal and Electronics Engineers, Inc and The Open Group. (This is
100 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
101 event of any discrepancy between this version and the original IEEE and
102 The Open Group Standard, the original IEEE and The Open Group Standard
103 is the referee document. The original Standard can be obtained online
104 at http://www.unix.org/online.html .
105
106 Any typographical or formatting errors that appear in this page are
107 most likely to have been introduced during the conversion of the source
108 files to man page format. To report such errors, see https://www.ker‐
109 nel.org/doc/man-pages/reporting_bugs.html .
110
111
112
113IEEE/The Open Group 2013 PUTS(3P)