-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_numalpha.c
More file actions
74 lines (66 loc) · 1.7 KB
/
ft_numalpha.c
File metadata and controls
74 lines (66 loc) · 1.7 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_numalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgalan-n <fgalan-n@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/02 11:29:49 by fgalan-n #+# #+# */
/* Updated: 2022/11/02 13:57:10 by fgalan-n ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_putchar(int c)
{
write(1, &c, 1);
return (1);
}
int ft_putstr(char *str)
{
int x;
x = 0;
if (!str)
return (ft_putstr("(null)"));
while (str[x])
{
ft_putchar(str[x]);
x++;
}
return (x);
}
int ft_int(int num)
{
int x;
x = 0;
if (num == -2147483648)
{
write(1, "-2147483648", 11);
return (11);
}
else if (num > 9)
{
x += ft_int(num / 10);
x += ft_int(num % 10);
}
else if (num < 0)
{
x += ft_putchar('-');
x += ft_int(-num);
}
else
x += ft_putchar(num + '0');
return (x);
}
int ft_unsigned_int(unsigned int long num)
{
int x;
x = 0;
if (num >= 10)
{
x += ft_unsigned_int(num / 10);
x += ft_putchar("0123456789"[num % 10]);
}
else
x += ft_putchar("0123456789"[num % 10]);
return (x);
}