-
Notifications
You must be signed in to change notification settings - Fork 0
/
conv_ouxx.c
57 lines (53 loc) · 1.88 KB
/
conv_ouxx.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* conv_ouxX.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ygokol <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/17 16:32:11 by ygokol #+# #+# */
/* Updated: 2017/03/27 19:00:03 by ygokol ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
void modif_ouxx(t_argmnt *tmp, va_list ap)
{
if (!ft_strcmp(tmp->modif, "hh") && ft_strchr("oOuU", tmp->type))
tmp->arg = ft_ultoa((unsigned char)va_arg(ap, unsigned int));
else if (!ft_strcmp(tmp->modif, "h"))
tmp->arg = ft_ultoa((unsigned short int)(va_arg(ap, unsigned int)));
else if (!ft_strcmp(tmp->modif, "l"))
tmp->arg = ft_ultoa(va_arg(ap, unsigned long int));
else if (!ft_strcmp(tmp->modif, "ll"))
tmp->arg = ft_ultoa(va_arg(ap, unsigned long long int));
else if (!ft_strcmp(tmp->modif, "j"))
tmp->arg = ft_ultoa(va_arg(ap, uintmax_t));
else if (!ft_strcmp(tmp->modif, "z"))
tmp->arg = ft_ultoa(va_arg(ap, unsigned long long int));
}
char *conv_o(unsigned long long n)
{
char *str;
int size;
unsigned long x;
x = n;
size = 0;
while (x > 7)
{
x /= 8;
size++;
}
str = (char *)malloc(sizeof(str) * (size + 1));
if (str)
{
str[size + 1] = '\0';
while (size >= 0)
{
x = n % 8;
str[size] = 48 + x;
n /= 8;
size--;
}
}
return (str);
}