-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversion_u.c
61 lines (54 loc) · 1.47 KB
/
conversion_u.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* conversion_u.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: araiva <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/27 20:38:06 by araiva #+# #+# */
/* Updated: 2022/03/27 20:38:07 by araiva ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include "myutils.h"
static char *uits(unsigned int d);
static int uilen(unsigned int d);
char *conversion_u(unsigned int d)
{
char *str;
str = uits(d);
if (!str)
return (NULL);
my_strrev(str);
return (str);
}
static char *uits(unsigned int d)
{
char *str;
int i;
i = 0;
str = ft_calloc(sizeof(char), uilen(d) + 1);
if (!str)
return (NULL);
str[0] = '0';
while (d > 0)
{
str[i] = (d % 10) + '0';
d = d / 10;
i++;
}
return (str);
}
static int uilen(unsigned int d)
{
int i;
i = 0;
if (d == 0)
return (1);
while (d > 0)
{
d = d / 10;
i++;
}
return (i);
}