-
Notifications
You must be signed in to change notification settings - Fork 0
/
format_function.c
71 lines (69 loc) · 1.6 KB
/
format_function.c
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
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#include "main.h"
/**
* handle_conversion_specifier - check which specifier is used
* @format: format string
* @args: va_list object
* Return: (len)
*/
int handle_conversion_specifier(const char *format, va_list args)
{
int i = 0;
int len = 0;
while (format[i] != '\0')
{
if (format[i] == '%')
{
if (format[i + 1] == 'c')
len += handle_char_specifier(args);
else if (format[i + 1] == 's')
len += handle_string_specifier(args);
else if (format[i + 1] == '%')
len += handle_percent_specifier();
else
len += handle_other_specifiers(format[i + 1], args);
i++;
}
else
{
write(1, &format[i], 1);
len++;
}
i++;
}
return (len);
} /* end function*/
/**
* handle_other_specifiers - handles other specifiers
* @args: va_list object
* @specifier: arguments
* Return: (format specifiers)
*
*/
int handle_other_specifiers(char specifier, va_list args)
{
if (specifier == 'd')
return (handle_decimal_specifier(args));
else if (specifier == 'i')
return (handle_integer_specifier(args));
else if (specifier == 'b')
return (handle_binary_specifier(args));
else if (specifier == 'u')
return (handle_unsigned_specifier(args));
else if (specifier == 'o')
return (handle_octal_specifier(args));
else if (specifier == 'x')
return ((handle_hex_specifier(args)));
else if (specifier == 'X')
return (handle_Hex_Specifier(args));
else if (specifier == 'p') /* handles address */
{
void *ptr = va_arg(args, void*);
handle_memory_address(ptr);
} /* end else */
else
return (0);
return (0);
} /* end function */