-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_itoa.c
More file actions
41 lines (38 loc) · 1.22 KB
/
ft_itoa.c
File metadata and controls
41 lines (38 loc) · 1.22 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
36
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mfrisby <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/07/11 13:10:10 by mfrisby #+# #+# */
/* Updated: 2017/07/11 13:10:12 by mfrisby ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
char *ft_itoa(int n)
{
char *s;
int div;
size_t i;
i = 0;
div = 1;
s = ft_strnew(11);
if (n == -2147483648)
s = "-2147483648";
else if (n < 0)
{
n *= -1;
s[i++] = '-';
}
while ((n / div) > 9 && ++i)
div *= 10;
while (n > 9)
{
s[i--] = n % 10 + '0';
n /= 10;
}
if (n >= 0)
s[i] = n + '0';
return (s);
}