-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_itoa_imp.c
62 lines (58 loc) · 1.61 KB
/
ft_itoa_imp.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
50
51
52
53
54
55
56
57
58
59
60
61
62
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ohachim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/14 10:52:14 by ohachim #+# #+# */
/* Updated: 2019/05/26 06:09:53 by ohachim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static char *ft_filltab(char *s, long long int n, int nn, long long int len)
{
if (n >= 0)
if (!(s = (char*)malloc(nn + 1)))
return (0);
if (n < 0)
if (!(s = (char*)malloc(nn + 2)))
return (0);
if (n < 0)
{
nn = 1;
s[0] = '-';
n = n * -1;
}
else
nn = 0;
while (len > 0)
{
s[nn++] = (((n > 0) ? (n / len) : (n / len) * -1) + '0');
n = n % len;
len = len / 10;
}
s[nn] = '\0';
return (s);
}
char *ft_itoa_imp(long long int n)
{
long long int conv;
long long int dec;
long long int fn;
int nn;
char *tab;
tab = NULL;
conv = n;
fn = conv;
dec = 1;
nn = 1;
while ((fn / 10) != 0)
{
dec = dec * 10;
nn++;
fn = fn / 10;
}
tab = ft_filltab(tab, conv, nn, dec);
return (tab);
}