maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_print_unsigned_dec.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_print_unsigned_dec.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: rocky <rmikhayl@student.42london.com> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/01/07 15:47:43 by rocky #+# #+# */
9/* Updated: 2024/01/07 15:47:43 by rocky ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "libft.h"
14
15int ft_num_len(unsigned int num)
16{
17 int len;
18
19 len = 0;
20 while (num != 0)
21 {
22 len++;
23 num = num / 10;
24 }
25 return (len);
26}
27
28char *ft_uitoa(unsigned int n)
29{
30 char *num;
31 int len;
32
33 len = ft_num_len(n);
34 num = (char *)malloc(sizeof(char) * (len + 1));
35 if (!num)
36 return (0);
37 num[len] = '\0';
38 while (n != 0)
39 {
40 num[len - 1] = n % 10 + 48;
41 n = n / 10;
42 len--;
43 }
44 return (num);
45}
46
47int ft_print_unsigned_dec(unsigned int n)
48{
49 int count;
50 char *num;
51
52 count = 0;
53 if (n == 0)
54 count += write(1, "0", 1);
55 else
56 {
57 num = ft_uitoa(n);
58 count += ft_print_str(num);
59 free(num);
60 }
61 return (count);
62}
int ft_num_len(unsigned int num)
char * ft_uitoa(unsigned int n)
int ft_print_unsigned_dec(unsigned int n)
int ft_print_str(char *str)