-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathman_3_printf
115 lines (85 loc) · 3.01 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
.TH _printf 1 "April 20, 2023" "version 1.2" "_printf man page"
.SH NAME
_printf - format and print data
.SH SYNOPSIS
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include "main.h"
int _printf(const char *format, ...);
.SH DESCRIPTION
_printf is a function that produces output according to a format. It writes the output under the control of a format string that specifies how subsequent arguments (or arguments accessed via the variable-length argument facilities of stdarg(3)) are converted for output.
The function executes according to the following options:
.I
.SS FORMAT SPECIFIERS:
.RS
A character that specifies the type of conversion to be applied. The format specifiers and their meanings are:
.IP %c
Prints a single character. The int argument is converted to an unsigned char, and the resulting character is written.
.IP %s
Prints a string. The const char * argument is expected to be a pointer to an array of character type (pointer to a string). Characters from the array are written up to (but not including) a terminating null byte ('\0').
.IP %d, %i
Prints a signed integer in decimal notation. The int argument is converted to signed decimal notation.
.IP %u
Prints an unsigned integer in decimal notation.
.IP %o
Prints an unsigned integer in octal notation.
.IP %x, %X
Prints an unsigned integer in hexadecimal notation. The letters 'abcdef' are used for %x conversions; the letters 'ABCDEF' are used for %X conversions.
.IP %p
Prints a pointer address in hexadecimal notation.
.IP %%
Prints a literal percent sign.
.I
.SS MODIFIERS:
.RS
A character that specifies the format of the argument to be printed. The modifiers and their meanings are:
.IP hh
Treats the corresponding argument as a signed or unsigned char.
.IP h
Treats the corresponding argument as a signed or unsigned short int.
.IP l
Treats the corresponding argument as a signed or unsigned long int.
.IP ll
Treats the corresponding argument as a signed or unsigned long long int.
.IP +
Prints a sign (+ or -) for signed numbers.
.IP ' '
A space is inserted before positive numbers.
.IP #
Used with o, x, and X conversions, the value is preceded with 0, 0x, or 0X respectively for values different than zero.
.IP 0
Left-pads the number with zeros instead of spaces.
.I
.SS CUSTOM CONVERSION SPECIFIERS:
.RS
.IP %b
Prints an unsigned integer in binary notation.
.IP %r
Prints a string in reverse.
.IP %R
Prints a string in ROT13 encryption.
.SH RETURN VALUE
Upon successful return, the _printf function returns the number of characters printed (excluding the null byte used to end output to strings).
If an output error is encountered, a negative value (-1) is returned.
.SH EXAMPLES:
.RS
.SS --------------
.I
.SS Character[%c]:
.RS
.SS --------------
.SS Input: _printf("This is a char: [%c]", 'C');
.SS Output: This is a char: [C]
.SS --------------
.I
.SS Literal String:
.RS
.SS --------------
.SS Input: _printf("Let's try to _printf a simple sentence");
.SS Output: Let's try to _printf a simple sentence
.SS --------------
.I
.SS Integers[%i]:
.RS
.