-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_utils.c
More file actions
60 lines (52 loc) · 1.55 KB
/
ft_printf_utils.c
File metadata and controls
60 lines (52 loc) · 1.55 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mjusta <mjusta@student.42prague.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/30 14:45:47 by mjusta #+# #+# */
/* Updated: 2025/06/02 16:07:08 by mjusta ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putchar(const char c)
{
write(1, &c, 1);
return (1);
}
int ft_putstr(const char *str)
{
int count;
if (!str)
return (ft_putstr("(null)"));
count = 0;
while (*str)
count += ft_putchar(*str++);
return (count);
}
int ft_putnbr(int n)
{
long num;
int count;
count = 0;
num = n;
if (num < 0)
{
count += ft_putchar('-');
num = -num;
}
if (num >= 10)
count += ft_putnbr(num / 10);
count += ft_putchar(num % 10 + '0');
return (count);
}
/*
#include <stdio.h>
int main(void)
{
char *str = "Hello 42";
printf(" is %i characters long\n", ft_putstr(str));
int nb = -2147483648;
printf(" is %i characters long\n", ft_putnbr(nb));
} */