-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibft_functions_3.c
82 lines (76 loc) · 1.73 KB
/
libft_functions_3.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft_functions_3.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfreitas <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/25 10:24:08 by jfreitas #+# #+# */
/* Updated: 2020/02/27 11:36:34 by jfreitas ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char const *s)
{
if (s)
{
while (*s != '\0')
{
ft_putchar(*s);
s++;
}
}
}
void ft_putnbr(int n)
{
if (n < 0)
{
ft_putchar('-');
n = -n;
}
if (n > 9)
{
ft_putnbr(n / 10);
ft_putnbr(n % 10);
}
else
ft_putchar(n + 48);
}
void ft_putnbr_unsigned(unsigned int n)
{
if (n > 4294967295 || n < 0)
return ;
if (n > 9)
{
ft_putnbr_unsigned(n / 10);
ft_putnbr_unsigned(n % 10);
}
else
ft_putchar(n + 48);
}
void ft_putnbr_long(long int n)
{
if (n < -9223372036854775807 - 1 || n > 9223372036854775807)
return ;
if (n == -9223372036854775807 - 1)
{
ft_putstr("-9223372036854775808");
return ;
}
if (n < 0)
{
ft_putchar('-');
n *= -n;
}
if (n > 9)
{
ft_putnbr_long(n / 10);
ft_putnbr_long(n % 10);
}
else
ft_putchar(n + 48);
}