-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_hexa1.c
49 lines (46 loc) · 1.34 KB
/
ft_hexa1.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_hexa1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbifenzi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/31 14:07:58 by mbifenzi #+# #+# */
/* Updated: 2020/01/13 17:43:52 by mbifenzi ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdarg.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "ft_printf.h"
char *hexa1(unsigned int i)
{
int j;
int k;
int len;
char *s;
k = 0;
j = i;
len = 0;
while (j > 0)
{
j = j / 16;
len++;
}
if(!(s = malloc(sizeof(char) * (len + 1))))
return(0);
s[len] = '\0';
len--;
while (len >= 0)
{
if (i % 16 >= 10)
s[len] = 65 + i % 16 - 10;
else
s[len] = i % 16 +'0';
i = i/ 16;
len--;
}
return(s);
}