-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_itoa.c
More file actions
35 lines (33 loc) · 1.19 KB
/
Copy pathft_itoa.c
File metadata and controls
35 lines (33 loc) · 1.19 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: danrodr3 <danrodr3@students.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/14 15:01:38 by danrodr3 #+# #+# */
/* Updated: 2025/10/14 18:34:08 by danrodr3 ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa(int n)
{
int i;
long tmp;
char result[12];
if (n == 0)
return (ft_strdup("0"));
tmp = n;
i = 11;
result[11] = '\0';
if (tmp < 0)
tmp *= -1;
while (tmp > 0)
{
result[i--] = (tmp % 10) + '0';
tmp /= 10;
}
if (n < 0)
result[i--] = '-';
return (ft_strdup(&result[i + 1]));
}