-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattribute_char.c
More file actions
67 lines (63 loc) · 1.23 KB
/
attribute_char.c
File metadata and controls
67 lines (63 loc) · 1.23 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
/*
** attribute_char.c for in /home/Kitero/delivery/PSU_2016_my_printf
**
** Made by Theo CLEMENT
** Login <Kitero@epitech.net>
**
** Started on Wed Nov 16 16:18:46 2016 Theo CLEMENT
** Last update Sun Nov 20 12:03:25 2016 Theo CLEMENT
*/
#include <stdarg.h>
#include "my.h"
int attribute_char(const char *str, int i, va_list ap, ...)
{
if (str[i] == '#')
{
if (str[i + 1] == 'o')
{
my_putchar('0');
my_put_nbr_base(va_arg(ap, unsigned int), 8, 0);
}
else if (str[i + 1] == 'x')
{
my_putstr("0x");
my_put_nbr_base(va_arg(ap, unsigned int), 16, 1);
}
else if (str[i + 1] == 'X')
{
my_putstr("0X");
my_put_nbr_base(va_arg(ap, unsigned int), 16, 2);
}
else
return (0);
return (1);
}
return (0);
}
int attribute_char2(const char *str, int i, va_list ap, ...)
{
int nbr;
if (str[i] == '+')
{
if (str[i + 1] == 'd' || str[i + 1] == 'i')
{
nbr = va_arg(ap, unsigned int);
if (nbr < 0)
my_put_nbr_normal(nbr);
else
{
my_putchar('+');
my_put_nbr_normal(nbr);
}
}
else if (str[i + 1] == 'p')
{
my_putstr("+0x");
my_put_nbr_p(va_arg(ap, unsigned long int));
}
else
return (0);
return (1);
}
return (0);
}