-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_utoa_base_bonus.c
33 lines (30 loc) · 1.17 KB
/
ft_utoa_base_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_utoa_base_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lrocca <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/03 13:32:36 by lrocca #+# #+# */
/* Updated: 2021/05/10 16:21:41 by lrocca ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_utoa_base(unsigned long long n, char *radix)
{
char *s;
size_t len;
int base;
base = ft_strlen(radix);
len = ft_numlen(n, base);
s = malloc(len + 1);
if (!s)
return (NULL);
s[len] = '\0';
while (n)
{
s[--len] = radix[n % base];
n /= base;
}
return (s);
}