-
Notifications
You must be signed in to change notification settings - Fork 0
/
printing_numbers.c
60 lines (53 loc) · 1.44 KB
/
printing_numbers.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printing_numbers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ael-maaz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/26 18:43:56 by ael-maaz #+# #+# */
/* Updated: 2024/01/26 18:47:33 by ael-maaz ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static void recurs(long n, int *index)
{
(*index)++;
if (n < 10)
ft_putchar(n + '0');
else
{
recurs(n / 10, index);
ft_putchar((n % 10) + '0');
}
}
int ft_put_u(unsigned int n)
{
int i;
i = 0;
recurs(n, &i);
return (i);
}
int ft_put_s(int n)
{
long nbr;
int count;
count = 0;
nbr = (long)n;
if (nbr >= 0)
recurs(nbr, &count);
else
{
count++;
ft_putchar('-');
recurs(-nbr, &count);
}
return (count);
}
int printing_numbers(long n, char c)
{
if (c == 'i' || c == 'd')
return (ft_put_s(n));
else
return (ft_put_u(n));
}