-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprint_functions_4.c
More file actions
82 lines (71 loc) · 1.39 KB
/
print_functions_4.c
File metadata and controls
82 lines (71 loc) · 1.39 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
#include "main.h"
/**
* conv_hexa_2dig - conv char to hexa
* @c: char to conv
* @count: flag to check for recursion
*
* Return: nothing(void)
*/
int conv_hexa_2dig(char c, int count)
{
int nb_c = 0;
if (c / 16)
{
count--;
nb_c += conv_hexa_2dig(c / 16, count);
}
if (count == 2)
nb_c += _putchar('0');
if (c % 16 < 10)
nb_c += _putchar(c % 16 + '0');
else
nb_c += _putchar(c % 16 - 10 + 'A');
return (nb_c);
}
/**
* print_string_ascii - print strings with non printable characters
*
* @ap: list of arguments from format
*
* Return: the nb of char printed
*/
int print_string_ascii(va_list ap)
{
int j, nb_c = 0;
char *s = va_arg(ap, char *);
if (!(s))
return (write(1, "(null)", 6));
for (j = 0; s[j]; j++)
if (s[j] > 0 && (s[j] < 32 || s[j] >= 127))
{
nb_c += _putchar('\\');
nb_c += _putchar('x');
nb_c += conv_hexa_2dig(s[j], 2);
}
else
nb_c += _putchar(s[j]);
return (nb_c);
}
/**
* print_pointer - cfr description
* @ap: va_list
* description: Specifier adapted for pointer or adress
* Return: number of hexadecimal value of adress printed
*/
int print_pointer(va_list ap)
{
int i = 1, nb_c = 0;
unsigned long int j = va_arg(ap, unsigned long int);
if (j == 0)
return (write(1, "(nil)", 5));
nb_c += _putchar('0');
nb_c += _putchar('x');
print_last_hexa_digit(j);
while (j / 16)
{
i++;
j = j / 16;
}
nb_c += i;
return (nb_c);
}