-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf_func.c
69 lines (61 loc) · 1.54 KB
/
ft_printf_func.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_func.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fozerdem <fozerdem@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 14:03:36 by fozerdem #+# #+# */
/* Updated: 2023/07/19 16:39:28 by fozerdem ### ########.tr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putchar(char c)
{
write(1, &c, 1);
return (1);
}
int ft_strlen(char *c)
{
int i;
i = 0;
while (c[i])
i++;
return (i);
}
int ft_putstr(char *c)
{
int res;
res = 0;
if (c != NULL)
{
write(1, c, ft_strlen(c));
res = ft_strlen(c);
}
else
{
write(1, "(null)", 6);
res = 6;
}
return (res);
}
int ft_putnbr(int n)
{
int result;
result = 0;
if (n == -2147483648)
return (ft_putstr("-2147483648"));
if (n >= 10)
{
result += ft_putnbr(n / 10);
result += ft_putchar((n % 10) + '0');
}
else if (n < 0)
{
result += ft_putchar('-');
result += ft_putnbr(-n);
}
else
result += ft_putchar(n + '0');
return (result);
}