-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprintf_utils.c
53 lines (46 loc) · 1.47 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printf_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcil <mcil@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/20 11:05:01 by mcil #+# #+# */
/* Updated: 2022/02/26 15:43:10 by mcil ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/libft.h"
#include "ft_printf.h"
#include <stdio.h>
int ft_putstr(char *str)
{
if (!str)
return (ft_putstr("(null)"));
return (write(1, str, ft_strlen(str)));
}
int ft_putchar(char c)
{
write(1, &c, 1);
return (1);
}
int ft_putpointer(void *ptr)
{
unsigned long ret;
int res;
ret = (unsigned long)ptr;
res = 0;
if (ret > 15)
res += ft_putpointer((void *)(ret / 16));
res += ft_putchar("0123456789abcdef"[ret % 16]);
return (res);
}
int ft_putnbr(int number)
{
char *num;
int len;
len = 0;
num = ft_itoa(number);
len += ft_putstr(num);
free(num);
return (len);
}