-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5_ascii
More file actions
49 lines (42 loc) · 896 Bytes
/
5_ascii
File metadata and controls
49 lines (42 loc) · 896 Bytes
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
#include "main.h"
/**
* print_ascii - print string with non-printable characters in hex format
* @arg: va_list argument containing the string
* Return: number of printed characters
*/
int print_ascii(va_list arg)
{
char *str = va_arg(arg, char *);
int count = 0, i;
if (!str)
str = "(null)";
for (i = 0; str[i]; i++)
{
if (str[i] < 32 || str[i] >= 127)
{
count += _putchar('\\');
count += _putchar('x');
va_list args
va_start(args, format);
count += print_HEX_S(args);
va_end(args);
}
else
{
count += _putchar(str[i]);
}
}
return (count);
}
/**
* print_HEX_S - print unsigned int in uppercase hexadecimal format
* @arg: va_list argument containing the unsigned int
* Return: number of printed characters
*/
int print_HEX_S(va_list arg)
{
unsigned int num = va_arg(arg, int);
int count = 0;
count += dectohex(num, 1);
return (count);
}