-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_utils.c
51 lines (46 loc) · 1.34 KB
/
ft_printf_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mokhan <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/05 20:29:03 by mokhan #+# #+# */
/* Updated: 2023/10/06 13:39:04 by mokhan ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_numlen(long long n, int base)
{
int len;
len = !n;
while (n)
{
n /= base;
len++;
}
return (len);
}
char *ft_itoap(long long n)
{
char *c;
bool sign;
long long len;
sign = n < 0;
len = ft_numlen(n, 10);
c = (char *)malloc(sizeof(char) * (len + 1));
if (!c)
return (NULL);
c[len] = '\0';
if (sign)
{
c[--len] = -(n % 10) + '0';
n = -(n / 10);
}
while (len--)
{
c[len] = n % 10 + '0';
n = n / 10;
}
return (c);
}