-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_o_x_X.c
71 lines (62 loc) · 1.18 KB
/
my_o_x_X.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
/*
** my_o_x_X.c for in /u/epitech_2012/brenne_t/cu/rendu/c/my_printf
**
** Made by thomas brennetot
** Login <[email protected]>
**
** Started on Fri Dec 28 15:51:02 2007 thomas brennetot
** Last update Fri Dec 28 16:37:58 2007 thomas brennetot
*/
#include <stdarg.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include "my_printf.h"
int my_putnbr_base(int nb, char *base)
{
int deb;
int fin;
int len;
len = my_strlen(base);
if (nb < 0)
{
my_putchar('-');
my_putnbr_base(-nb, base);
}
else
{
fin = nb % len;
deb = (nb - fin) / len;
if (deb != 0)
my_putnbr_base(deb, base);
my_putchar(base[fin]);
}
return (0);
}
void my_printf_o(char *str, va_list *args)
{
char *base;
int nb;
base = "01234567";
nb = va_arg(*args, int);
my_putnbr_base(nb, base);
str++;
}
void my_printf_x(char *str, va_list *args)
{
char *base;
int nb;
base = "0123456789abcdef";
nb = va_arg(*args, int);
my_putnbr_base(nb, base);
str++;
}
void my_printf_X(char *str, va_list *args)
{
char *base;
int nb;
base = "0123456789ABCDEF";
nb = va_arg(*args, int);
my_putnbr_base(nb, base);
str++;
}