Repository navigation
Expand file tree
/
Copy pathman_3_printf
More file actions
executable file
·88 lines (51 loc) · 3.7 KB
/
Copy pathman_3_printf
File metadata and controls
executable file
·88 lines (51 loc) · 3.7 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
.TH _PRINTF 3 "October 2018" "0.1" "Holberton School 0x10. C - _printf"
.SH NAME
.B _printf\fR \- formatted output conversion
.SH SYNOPSIS
.B #include \fB"holberton.h"
.B int printf(const char *\fIformat\fB, ...);
.SH DESCRIPTION
The function
\fB_printf()\fR writes output to \fIstdout\fR, the standard output. The function writes the output under the control of a \fIformat\fR string that specifies how subsequent arguments (accessed via the variable-length argument facilities of stdarg) are converted for output.
.B Return value
Upon successful return, \fB_printf()\fR returns the number of characters printed (excluding the null byte used to end output to strings).
If an output error is encountered, -1 is returned.
.B Format of the format string
The format string is a constant character string composed of zero or more directives: ordinary characters (not \fB%\fR) which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent arguments. Conversion specification is introduced by the character \fB%\fR and ends with a \fIconversion specifier\fR. The arguments must correspond with the conversion specifier, and are used in the order given.
.B The conversion specifier
A character that specifies the type of conversion to be applied. The conversion specifiers and their meaning are:
.B d, i
The \fIint\fR argument is converted to signed decimal notation.
.B b
The \fIunsigned int\fR argument is converted to binary.
.B o, u, x, X
The \fIunsigned int\fR argument is converted to unsigned octal (\fBo\fR), unsigned decimal (\fBu\fR), or unsigned hexadecimal (\fBx\fR and \fBX\fR) notation. The letters \fBabcdef\fR are used for \fBx\fR conversions; the letters \fBABCDEF\fR are used for \fBX\fR conversions.
.B c
The \fIint\fR argument is converted to an \fIunsigned char\fR, and the resulting character is written.
.B s
The \fIconst char *\fR argument is expected to be a pointer to a character array (pointer to a string). Characters from the array are written starting from the first element of the array and ending at, but not including, the terminating null byte ('\\0').
.B S
Identical to the \fBS\fR conversion specifier, except any non-printable characters in the array (ie. characters with an ASCII value < 32 or >= 127) are written as \fB\\x\fR followed by the ASCII code value in hexadecimal (upper case, two characters).
.B r
Identical to the \fBs\fR conversion specifier, except characters from the array are written in reverse, starting from (but not including) the terminating null byte ('\\0') and ending at the first element of the array.
.B R
Identical to the \fBs\fR conversion specifier, except each character of the array is converted to its corresponding character in ROT13 before breing written.
.B p
The address of the argument is written. The address is written in hexadecimal with a leading \fI0x\fR.
.B %
A '%' is written. No argument is converted. The complete conversion specification is '%%'.
.SH BUGS
Code such as \fB_printf(\fIfoo\fB);\fR possibly indicates a bug, since \fIfoo\fR may contain a % character.
.SH EXAMPLE
To print the address of Holberton School in the form "972 Mission St., San Francisco, CA 94103", followed by a new line, where \fIstreet\fR, \fIcity\fR, and \fIstate\fR are pointers to strings:
.RS
#include "holberton.h"
int main(void)
char *street = "Mission St.", *city = "San Francisco", *state = "CA";
printf("%d %s, %s, %s, %d\\n", 972, street, city, state, 94103);
.RE
.SH SEE ALSO
printf(3)
The \fB_printf()\fR function emulates functionality of the C standard library function \fBprintf()\fR. This man page borrows from the corresponding Linux man page printf(3).
.SH AUTHOR
Brennan D Baraban and Michael Klein