maxishell
Implementation of a shell for Linux-like systems
Loading...
Searching...
No Matches
ft_itoa.c File Reference
#include "libft.h"
Include dependency graph for ft_itoa.c:

Go to the source code of this file.

Functions

static int count_digits (int n)
 
char * ft_itoa (int n)
 

Function Documentation

◆ count_digits()

static int count_digits ( int  n)
static

Definition at line 23 of file ft_itoa.c.

24{
25 int count;
26
27 count = 0;
28 if (n <= 0)
29 count = 1;
30 else
31 count = 0;
32 while (n != 0)
33 {
34 count++;
35 n /= 10;
36 }
37 return (count);
38}

Referenced by ft_itoa().

Here is the caller graph for this function:

◆ ft_itoa()

char * ft_itoa ( int  n)

Definition at line 40 of file ft_itoa.c.

41{
42 int len;
43 char *str;
44
45 if (n == INT_MIN)
46 return (ft_strdup("-2147483648"));
47 if (n == 0)
48 return (ft_strdup("0"));
49 len = count_digits(n);
50 str = (char *)malloc(len + 1);
51 if (!str)
52 return (NULL);
53 str[len--] = '\0';
54 if (n < 0)
55 {
56 str[0] = '-';
57 n = -n;
58 }
59 while (n)
60 {
61 str[len--] = n % 10 + '0';
62 n /= 10;
63 }
64 return (str);
65}
static int count_digits(int n)
Definition ft_itoa.c:23
char * ft_strdup(const char *s)
Definition ft_strdup.c:23

References count_digits(), and ft_strdup().

Referenced by builtin_env(), ft_print_int(), handle_exit(), set_shell_var_handler(), and shell_variable_update().

Here is the call graph for this function:
Here is the caller graph for this function: