forked from suhearsawho/printf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathman_3_printf
More file actions
executable file
·136 lines (127 loc) · 4.23 KB
/
Copy pathman_3_printf
File metadata and controls
executable file
·136 lines (127 loc) · 4.23 KB
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
129
130
131
132
133
134
135
136
.TH _printf 3 "24 October 2018" "_printf man page"
.SH NAME
_printf \- formats and prints arguments to the standard output.
.SH SYNOPSIS
.B
#include "holberton.h"
.LP
.B _printf
.B (const char *format, ...);
.SH DESCRIPTION
The _printf() function formats and prints arguments to the standard output based on the format string.
Any number of arguments can follow the format string. These arguments will replace the conversion specifiers in the _printf() function.
.LP
.B Return Value
.RS 3
The _printf() function returns the number of characters printed to the standard output. A null character will not be printed to the screen, and will not be considered in the character count.
.LP
.RE
.B Format String
.RS 3
The format string of _printf() contains ordinary characters, characters to be printed to the standard output, and conversion specifications.
.LP
Conversion specifications begins with a % symbol and end with a conversion character. The conversion specification determines the format and conversion of the arguments that follow the format string.
These arguments are optional, and should only be necessary when a conversion specification is present in the format string.
.LP
The following lists the various flags and conversion characters that are available for the _printf() function. If used, they must follow the percent symbol in the order they are listed.
.LP
.B Flags
.LP
The following flags can be mixed and matched in any order.
.LP
.RS 3
.B '-'
.RS 3
Adds left adjustment to the converted argument.
.LP
.RE
.B '+'
.RS 3
Adds a sign to a number to be printed.
.LP
.RE
.B 'space'
.RS 3
Given that the first printed character is not a sign, a space will be added.
.LP
.RE
.B '0'
.RS 3
Used to pad the field width with leading zeros.
.RE
.RE
.LP
.B Conversion Specifiers/Characters
.LP
The following characters determine the conversion and format of the arguments that follow the mandatory format string of printf().
.LP
.RS 3
.B %c
.RS 3
Accepts an argument type of int. Converts to an unsigned char type and prints a single character to the standard output.
.LP
.RE
.B %s
.RS 3
Accepts an argument type of char *. Prints the specified characters from the string until a null character is reached.
.LP
.RE
.B %d, %i
.RS 3
Accepts an argument type of int. Prints the signed decimal notation to the standard output.
.LP
.RE
.B %b
.RS 3
Accepts an argument type of unsigned int. Prints the binary format of the argument to the standard output.
.LP
.RE
.B %u
.RS 3
Accepts an argument type of int. Prints the unsigned decimal notation to the standard output.
.LP
.RE
.B %o
.RS 3
Accepts an argument type of int. Prints the unsigned octal notation to the standard output.
.LP
.RE
.B %X, %x
.RS 3
Accepts an argument type of int. Prints the unsigned hexadecimal notation to the standard output. 'X' indicates that capital letters will be used (A-F). 'x' indicates that lowercase letters will be used (a-f).
.LP
.RE
.B %S
.RS 3
Accepts an argument type of char *. Prints the characters(non-printable and printable) of the string to the standard output. Nonprintable characters will be printed with the ASCII code value in hexadecimal.
.LP
.RE
.B %p
.RS 3
Accepts an argument type of void *. Prints the address of a variable.
.LP
.RE
.B %r
.RS 3
Accepts an argument type of char *. Prints the characters of a string in reverse.
.LP
.RE
.B %R
.RS 3
Accepts an argument type of char *. Prints the characters of a string in rot13.
.LP
.RE
.B %%
.RS 3
Accepts no argument. Prints a percent sign.
.LP
.RE
.B %(invalid conversion character)
.RS 3
Accepts no argument. In the case that an invalid conversion character is placed after the percentage sign, the percentage sign and character will be printed onto the output screen.
.SH BUGS
The _printf() function returns the number of characters printed to the output screen. As a result, users must be careful to not overflow the function by inserting an excessively long format string or too many input arguments.
.LP
In the event that conversion specifiers are present in the format string, but no arguments are provided, then a possible segmentation error might occur. Because the variable type, va_list, is unable to detect the end of the variable argument list, there are no means of avoiding this issue in the _printf() function.
.SH AUTHOR
Christopher Choe and Susan Su