-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_utoa_base.c
38 lines (35 loc) · 1.28 KB
/
ft_utoa_base.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_utoa_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vbrazas <vbrazas@student.unit.ua> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/02/08 00:11:44 by vbrazas #+# #+# */
/* Updated: 2018/08/14 15:47:45 by vbrazas ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_utoa_base(size_t value, const int base, const bool is_upperсase)
{
int j;
size_t b;
char *res;
if (base > 16 || base < 2)
return (0);
j = 1;
b = value;
while (b /= base)
j++;
b = value;
res = (char *)malloc(sizeof(char) * j);
res[j--] = '\0';
if (value == 0)
res[0] = '0';
while (b)
{
res[j--] = ft_itoc(b % base, is_upperсase);
b /= base;
}
return (res);
}