-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathman_printf
72 lines (54 loc) · 1.71 KB
/
man_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
NAME :
_printf
SYNOPSIS :
#include "main.h"
int _printf(const char *format, ...)
DESCRIPTION :
_printf is a custom implementation of printf. The function _printf produces output according to a format. The function
_printf writes output to stdout
FUNCTION PROTOTYPES:
int _printf(const char *format, ...);
int (*pick_printer(char c))(va_list args);
int print_c(va_list args);
int print_s(va_list args);
int print_prcnt(va_list args);
int print_n(va_list args);
RETURN VALUE :
Returns the number of characters printed (null byte excluded).
FORMAT :
Format is a character string. The format string is composed of zero or more directives. You can write plain text or use the
conversion specifiers listed below to format the arguments passed to the function.
CONVERSION SPECIFIER :
- %c : print a char
- %s : print a string
- %d and %i : print a number
- %% : print a single '%' char
BUGS :
No known bugs.
EXAMPLE :
Here are examples of the function being used for the 5 handled conversion specifiers:
Single character printing :
Expected output: A
printf("%c", 'A') -> : A
_printf("%c", 'A') -> : A
printf returned: 1, _printf returned: 1
String printing :
Expected output: Hello
printf("%s", 'Hello') -> : Hello
_printf("%s", 'Hello') -> : Hello
printf returned: 5, _printf returned: 5
Int printing :
Expected output: 15
printf("%i", 15) -> : 15
_printf("%i", 15) -> : 15
printf returned: 2, _printf returned: 2
Negative int printing :
Expected output: 15
printf("%d", -15) -> : -15
_printf("%d", -15) -> : -15
printf returned: 3, _printf returned: 3
Percentage printing :
Expected output: %
printf("%%") -> : %
_printf("%%") -> : %
printf returned: 1, _printf returned: 1