Repository navigation
Expand file tree
/
Copy pathft_ulltoa.c
More file actions
52 lines (46 loc) · 1.41 KB
/
Copy pathft_ulltoa.c
File metadata and controls
52 lines (46 loc) · 1.41 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ulltoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tamarant <tamarant@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/05 17:32:46 by tamarant #+# #+# */
/* Updated: 2020/04/07 21:31:59 by mac ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int nbr_len(unsigned long long int n)
{
int len;
len = 1;
while (n > 9)
{
n = n / 10;
len++;
}
return (len);
}
static char ft_str_int(char *s, unsigned long long int n, int len)
{
while (len--)
{
s[len] = (n % 10) + 48;
n = n / 10;
}
return ((char)s);
}
char *ft_ulltoa(unsigned long long int n)
{
int len;
char *res;
if (n <= 18446744073709551615ull)
{
len = nbr_len(n);
if (!(res = ft_memalloc(len + 1)))
return (NULL);
ft_str_int(res, n, len);
return (res);
}
return (NULL);
}