-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction1.c
More file actions
75 lines (67 loc) · 1.52 KB
/
function1.c
File metadata and controls
75 lines (67 loc) · 1.52 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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* function1.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: azaghlou <azaghlou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/01 12:04:48 by azaghlou #+# #+# */
/* Updated: 2022/11/03 12:29:20 by azaghlou ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putchar(char c)
{
write(1, &c, 1);
return (1);
}
int ft_putstr(char *s)
{
int i;
i = 0;
if (!s)
return (ft_putstr("(null)"));
while (s[i] != '\0')
{
i += ft_putchar(s[i]);
}
return (i);
}
int len_nbr(long b)
{
int i;
i = 0;
if (b == 0)
i++;
if (b < 0)
b = -b;
while (b > 0)
{
b /= 10;
i++;
}
return (i);
}
int ft_putnbr(int b)
{
long a;
int i;
a = b;
i = 0;
if (a == -2147483648)
return (ft_putstr("-2147483648"));
if (a < 0)
{
a = -a;
ft_putchar('-');
i++;
}
if (a >= 10)
{
ft_putnbr(a / 10);
ft_putnbr(a % 10);
}
else
ft_putchar(a + '0');
return (len_nbr(a) + i);
}