-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
92 lines (80 loc) · 1.3 KB
/
_printf.c
File metadata and controls
92 lines (80 loc) · 1.3 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
#include "main.h"
/**
* h_address - handle printing the address.
* @p: the address
*
* Return: the len.
*/
int h_address(unsigned long p)
{
int len = 0;
if (!p)
return (p_string("(nil)"));
len += p_char('0');
len += p_char('x');
len += p_address(p, 0);
return (len);
}
/**
* p_r_string - prints reversed string.
* @s: the the string
*
* Return: len.
*/
int p_r_string(char *s)
{
int i, len = 0;
for (i = (int)strlen(s) - 1; i >= 0; i--)
len += p_char(s[i]);
return (len);
}
/**
* p_R_string - prints the rot13'ed string.
* @s: the the string
*
* Return: len.
*/
int p_R_string(char *s)
{
int i, len = 0;
for (i = 0; i < (int)strlen(s); i++)
{
if (isalpha(s[i]))
{
if (s[i] < 'N' || (s[i] > 'Z' && s[i] < 'n'))
len += p_char(s[i] + 13);
else
len += p_char(s[i] - 13);
}
else
len += p_char(s[i]);
}
return (len);
}
/**
* _printf - print.
* @format: the format
*
* Return: the number of chars
*/
int _printf(const char *format, ...)
{
unsigned int i, len = 0;
va_list args;
if (format == NULL)
return (-1);
va_start(args, format);
for (i = 0; format[i]; i++)
{
if (format[i] != '%')
{
len += p_char(format[i]);
continue;
}
if (i++ == strlen(format) - 1)
return (-1);
len += specifier(format[i], args);
}
va_end(args);
return (len);
}