-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_utils.c
81 lines (71 loc) · 1.75 KB
/
ft_printf_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lpalacio <lpalacio@student.42madrid> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/19 20:09:21 by lpalacio #+# #+# */
/* Updated: 2023/09/24 20:27:01 by lpalacio ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
size_t ft_strlen(const char *s)
{
size_t n;
n = 0;
while (s[n] != 0)
n ++;
return (n);
}
int ft_putchar_fd(int c, int fd)
{
return (write (fd, &c, 1));
}
void ft_putint_fd(int n, int fd)
{
char c;
if (n < 0)
{
ft_putchar_fd ('-', fd);
n = -n;
}
c = '0' + n;
ft_putchar_fd(c, fd);
return ;
}
void ft_putnbr_fd(int n, int fd)
{
int num;
num = 0;
if (n < 10 && n > -10)
ft_putint_fd(n, fd);
if (n <= -10)
{
num = -(n % 10);
n = n / 10;
ft_putnbr_fd(n, fd);
ft_putint_fd(num, fd);
}
else if (n >= 10)
{
num = n % 10;
n = n / 10;
ft_putnbr_fd(n, fd);
ft_putint_fd(num, fd);
}
return ;
}
int count_printnbr(int n)
{
int count;
count = 1;
if (n < 0)
count ++;
while (n >= 10 || n <= -10)
{
n = n / 10;
count ++;
}
return (count);
}