-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr.c
89 lines (79 loc) · 1.66 KB
/
ft_putnbr.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asarandi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/12 00:42:17 by asarandi #+# #+# */
/* Updated: 2017/12/27 16:58:47 by asarandi ### ########.fr */
/* */
/* ************************************************************************** */
#include "filler.h"
int ft_atoi(char *str)
{
int i;
int result;
i = 0;
result = 0;
while ((str[i] >= '0') && (str[i] <= '9'))
{
result *= 10;
result += str[i] - '0';
i++;
}
return (result);
}
int ft_isdigit(int c)
{
if ((c >= '0') && (c <= '9'))
return (1);
else
return (0);
}
int ft_itoa_len2(long n)
{
int i;
if (n == 0)
return (1);
i = 0;
while (n)
{
n /= 10;
i++;
}
return (i);
}
char *ft_itoa2(long n, char *m)
{
int neg;
int i;
neg = 0;
if (n < 0)
{
n = -n;
neg = 1;
}
i = ft_itoa_len2(n) + neg;
m[i--] = 0;
if (!n)
m[i] = '0';
while (n)
{
m[i--] = (n % 10) + '0';
n /= 10;
}
if (neg)
m[i] = '-';
return (m);
}
void ft_putnbr(int n)
{
char m[200];
int i;
i = 0;
while (i < 200)
m[i++] = 0;
ft_itoa2(n, m);
ft_putstr(m);
}