-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdandi.c
More file actions
90 lines (79 loc) · 1.69 KB
/
dandi.c
File metadata and controls
90 lines (79 loc) · 1.69 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* ************************************************************************** */
/* */
/* :::::::: */
/* dandi.c :+: :+: */
/* +:+ */
/* By: cstaats <cstaats@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2021/10/25 12:10:41 by cstaats #+# #+# */
/* Updated: 2021/12/02 16:59:39 by cstaats ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
#include <limits.h>
int ft_putchar_fd(char c, int fd)
{
static int cnt;
cnt = 0;
if (fd >= 0)
{
write(fd, &c, 1);
cnt++;
}
return (cnt);
}
int ft_putstr_fd(char *s, int fd)
{
if (s && fd >= 0)
write(fd, s, ft_strlen(s));
return (0);
}
int ft_strlen(char const *str)
{
int cnt;
cnt = 0;
while (str[cnt] != 0)
{
cnt++;
}
return (cnt);
}
int intlen(int a)
{
int cnt;
cnt = 0;
if (a == 0)
return (1);
if (a < 0)
cnt++;
while (a != 0)
{
a = (a / 10);
cnt++;
}
return (cnt);
}
void dandi(int n, int fd)
{
if (n == INT_MIN)
{
ft_putstr_fd("-2147483648", fd);
}
else if (n == 0)
{
ft_putstr_fd("0", fd);
}
else
{
if (n < 0)
{
ft_putchar_fd('-', fd);
n = n * -1;
}
if (n > 9)
{
dandi(n / 10, fd);
}
ft_putchar_fd((n % 10) + '0', fd);
}
}