-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_basics.c
71 lines (65 loc) · 1.68 KB
/
ft_basics.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_basics.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gmacias- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/23 16:13:06 by gmacias- #+# #+# */
/* Updated: 2022/02/23 19:26:08 by gmacias- ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_print_string(char *str)
{
int size;
size = 0;
if (str == 0)
{
return (ft_print_string("(null)"));
}
while (str[size])
{
size += ft_print_character(str[size]);
}
return (size);
}
int ft_print_number(int n)
{
int size;
size = 0;
if (n == 0)
size += ft_print_character('0');
if (n == -2147483648)
{
size += ft_print_string("-2147483648");
return (size);
}
if (n < 0)
{
size += ft_print_character('-');
n = -n;
}
if (n > 0)
size += ft_print_unsigned((unsigned int)n);
return (size);
}
int ft_print_unsigned(unsigned int n)
{
int size;
size = 0;
if (n == 0)
size += ft_print_character('0');
else
{
if (n / 10 != 0)
ft_print_unsigned(n / 10);
ft_print_character((n % 10) + '0');
while (n > 0)
{
n /= 10;
size++;
}
}
return (size);
}