char *ft_itoa(int n) { int result; char *min_str; int len; min_str = "-2147483648"; len = 0; result = 0; if (n == -2147483648) return (min_str); len = ft_nbr_char(n); if (len == 0) len = 1; min_str = ft_mall_str(len); if (n < 0) n = n * -1; while (n > 10) { result = n % 10; min_str[len-- - 1] = result + 48; n = n / 10; } min_str[len-- - 1] = n + 48; if (len == 1 && min_str[1] != '\0') min_str[0] = '-'; return (min_str); }
char *ft_itoa(int n) { int i; long value; char *p_str; i = ft_nbr_char(n) + 1; if (!(p_str = (char *)malloc(sizeof(*p_str) * i))) return (NULL); if ((value = n) < 0) value = -value; p_str[--i] = '\0'; while (value / 10) { p_str[--i] = (value % 10) + '0'; value = value / 10; } p_str[--i] = value + '0'; if (n < 0) p_str[--i] = '-'; return (p_str); }