-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_iwtoa.c
39 lines (36 loc) · 1.26 KB
/
ft_iwtoa.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iwtoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lenzo-pe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/31 13:49:34 by lenzo-pe #+# #+# */
/* Updated: 2021/05/07 17:22:20 by lenzo-pe ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_conv.h"
char *ft_iwtoa(int n, size_t w)
{
char *str;
char *ptr;
size_t len;
len = ft_nbrlen(n);
if (n < 0)
len++;
if (w > len)
w -= len;
else
w = 0;
str = (char *)malloc(sizeof(char) * (len + w + 1));
if (!str)
return (NULL);
ptr = str;
if (n < 0)
*str++ = '-';
ft_memset(str, '0', w);
n = ft_abs(n);
ft_nbrcpy(str + w, n);
str[len + w] = '\0';
return (ptr);
}