-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_utlis_2.c
82 lines (74 loc) · 2 KB
/
print_utlis_2.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
72
73
74
75
76
77
78
79
80
81
82
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_utlis_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sfathima <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/10 13:38:20 by sfathima #+# #+# */
/* Updated: 2021/11/11 13:40:11 by sfathima ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_print_int(long n, int count)
{
unsigned int nbr;
nbr = n;
if (n < 0)
{
count = ft_print_char('-', count);
nbr = -n;
}
if (nbr >= 10)
count = ft_print_int(nbr / 10, count);
count = ft_print_char((nbr % 10 + '0'), count);
return (count);
}
int ft_check_hex(unsigned int nbr, int count, char c)
{
if (nbr == 0)
{
count = ft_print_char('0', count);
return (count);
}
else
count = ft_print_hex(nbr, count, c);
return (count);
}
int ft_print_hex(unsigned int nbr, int count, char c)
{
unsigned int rem;
rem = 0;
if (nbr)
{
rem = nbr % 16;
count = ft_print_hex(nbr / 16, count, c);
if (rem < 10)
count = ft_print_char(rem + 48, count);
else
{
if (c == 'x')
count = ft_print_char(rem + 55 + 32, count);
else
count = ft_print_char(rem + 55, count);
}
}
return (count);
}
int ft_print_u(unsigned int nbr, int count)
{
if (nbr < 0)
{
nbr = 4294967296 + nbr;
count = ft_print_int(nbr, count);
}
else
count = ft_print_int(nbr, count);
return (count);
}
int ft_isalpha(int c)
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
return (1);
return (0);
}