-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_uitoa.c
50 lines (45 loc) · 1.34 KB
/
ft_uitoa.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_uitoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eschirni <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/06 17:31:25 by eschirni #+# #+# */
/* Updated: 2021/08/24 16:50:51 by eschirni ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
#include <stdlib.h>
static int ft_get_size(unsigned int ln)
{
int size;
size = 1;
while (ln / 10 != 0)
{
size++;
ln /= 10;
}
return (size);
}
char *ft_uitoa(unsigned int n)
{
char *c;
int size;
int i;
size = ft_get_size(n);
c = malloc(size + 1);
if (c == NULL)
return (NULL);
c[size] = '\0';
if (n == 0)
c[0] = '0';
i = 1;
while (i < size + 1 && n != 0)
{
c[size - i] = (n % 10) + '0';
n /= 10;
i++;
}
return (c);
}