-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathman_3_printf
128 lines (112 loc) · 4.29 KB
/
man_3_printf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
.\" Manpage for _printf
.\" contact dureaupierre53@gmail.com or dutertre.alexandre@laposte.net to correct error or typos
.TH _printf 3 "15 mars 2022" "1.0" "_printf man page"
.SH NAME
_printf \- formatted output conversion
.SH SYNOPSIS
\fB #include "main.h"
\fB #include <stdarg.h>
\fB #include <stdlib.h>
\fB #include <unistd.h>
\fB #include <string.h>
\fB int _printf(const char *format, ...);
.SH DESCRIPTION
.SS Definition:
The function _printf write the output according to a format to stdout, the standard output. The output produced depends on the format. _printf is a variadic
function, meaning it can take a variable number of arguments.
.SS Format of the format string:
The format string is a character string, beginning and ending with a double quote ("). The format string is composed of zero or more directives:
ordinary characters, which are copied unchanged to the output stream, and conversion specifiers, each of which results in fetching zero or
more subsequent arguments. Each conversion specification is introduced by the character %, and ends with a conversion specifier. In between
there may be zero or more flags.
Example : _printf("Hello everyone at %s", "Holberton School"); => The format string is "Hello everyone at %s".
.SS Variable arguments:
The variable arguments must correspond in order to the conversion specifiers that are inside the format string.
.SS Flag characters:
The character % is followed by zero or more of the following flags:
.TP
\fB+\fP
A sign (+ or -) is placed before a number produced by a signed conversion. If the ' ' flag is after a + flag, the + flag overwrite the space flag.
.TP
\fB' '\fP
(a space) A blank space is put before the number if the number is positive.
.TP
\fB#\fP
The value takes an alternate form. For o conversions, the first character of the output is 0 except if the number to be printed is not zero already. In case of a x or X
conversions, if the number to output is different of zero, 0x (in case of x) or OX (in case of X) are the first characters to be printed before the number.
.SS Conversion specifiers:
A characters that specifies the type of conversion to be applied. The different specifiers supported are:
.TP
\fBc\fP
The int argument is converted to an unsigned char, and the resulting character is printed according to the ASCII value.
.TP
\fBs\fP
The char* argument is expected to be a pointer to an array of character type (pointer to a string). Characters from the array are printed up to a terminating
null byte (\\0) excluded.
.TP
\fB%\fP
A % is printed. The conversion specification is %% to print a single %.
.TP
\fBd, i\fP
The int argument is converted to signed decimal notation.
.TP
\fBb\fP
Print an unsigned integer as binary (01) \- Doesn't exist on the real printf.
.TP
\fBu\fP
Print an unsigned integer (0 to 4,294,967,295).
.TP
\fBo\fP
Print an unsigned integer in base 8.
.TP
\fBx\fP
Print an unsigned integer in base 16 with the letters in lowercase (abcdef).
.TP
\fBX\fP
Same as x, but the letters are in uppercase (ABCDEF).
.TP
\fBS\fP
Same as s, but the non-printable characters (32 < ASCII value >= 127) appear as \\x and their hexadecimal value in uppercase with 2 characters
\- Doesn't exist on the real printf.
.TP
\fBp\fP
Print the address of a variable.
.TP
\fBr\fP
Print a string in reverse. \- Doesn't exist on the real printf.
.TP
\fBR\fP
Print a string encoded in rot13. \- Doesn't exist on the real printf.
.SH RETURN VALUE:
If successful, _printf would return the number of characters the function printed, excluding the '\\0' indicating the end of the string.
.sp 0
If _printf failed, it would return the value -1.
.SH EXAMPLES
.sp
_printf("%i", 2); \fBOutput : 2\fP
.sp
_printf("%b", 7); \fBOutput : 111\fP
.sp
_printf("%u", 3147593600); \fBOutput : 3147593600\fP
.sp
_printf("%o", 90); \fBOutput : 132\fP
.sp
_printf("%x", 908); \fBOutput : 38c\fP
.sp
_printf("%X", 1115); \fBOutput : 45B\fP
.sp
_printf("%S", "Best\\nSchool"); \fBOutput : Best\\x0ASchool\fP
.sp
_printf("%p", (void *)0x7ffe637541f0); \fBOutput : 0x7ffe637541f0\fP
.sp
_printf("%r", "Hello!"); \fBOutput : !olleH\fP
.sp
_printf("%R", "My message"); \fBOutput : Zl zrffntr\fP
.SH SEE ALSO
\fBman page of the real printf function\fP
.sp 0
https://man7.org/linux/man-pages/man3/printf.3.html
.SH AUTHORS
Alexandre DUTERTRE, Pierre DUREAU and Jay MESNIL
.SH COPYRIGHTS
©HOLBERTON SCHOOL LAVAL