-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_itoa_base.c
35 lines (32 loc) · 1.25 KB
/
ft_itoa_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ewilliam <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 11:55:28 by ewilliam #+# #+# */
/* Updated: 2017/01/09 12:13:56 by ewilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa_base(int n, const size_t base)
{
char *sym;
char *arr;
char *head;
unsigned long num;
sym = "0123456789ABCDEF";
num = n;
if (!(arr = ft_strnew(ft_countplaces(num, base))))
return (NULL);
head = arr;
while (num)
{
*arr++ = *(sym + (num % base));
num /= base;
}
*arr = '\0';
ft_strrev(head, ft_strlen(head));
return (head);
}