-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_putunsint.c
More file actions
59 lines (52 loc) · 1.49 KB
/
Copy pathft_putunsint.c
File metadata and controls
59 lines (52 loc) · 1.49 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putunsint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alvutina <alvutina@student.42berlin.d +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/06 09:22:42 by alvutina #+# #+# */
/* Updated: 2024/05/06 09:22:52 by alvutina ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_strlen_unint(unsigned int n)
{
int len;
len = 0;
if (n == 0)
len = 1;
while (n > 0)
{
n = n / 10;
len++;
}
return (len);
}
char *ft_itoa_unint(unsigned int n)
{
char *str;
int i;
int len;
len = ft_strlen_unint(n);
str = malloc(sizeof(char) * (len + 1));
if (!str)
return (NULL);
i = -1;
if (n == 0)
str[0] = '0';
while (n > 0)
{
str[len - (++i) - 1] = (char)(n % 10 + 48);
n = n / 10;
}
str[len] = '\0';
return (str);
}
void ft_putunsint(unsigned int n, size_t *counter)
{
char *str;
str = ft_itoa_unint(n);
ft_putstr_new(str, counter);
free(str);
}