-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_itoa.c
41 lines (38 loc) · 1.33 KB
/
ft_itoa.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: matlopes <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 09:39:48 by matlopes #+# #+# */
/* Updated: 2023/11/27 12:34:02 by matlopes ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa(int n)
{
char *pointer;
int counter;
int signal;
long int value;
value = (long int)n;
counter = ft_intlen(value);
pointer = malloc((counter + 1) * sizeof(char));
if (!pointer)
return (NULL);
signal = 0;
if (value < 0)
{
pointer[0] = '-';
value *= -1;
signal = 1;
}
pointer[counter--] = '\0';
while (counter >= signal)
{
pointer[counter--] = ((value % 10) + '0');
value /= 10;
}
return (pointer);
}