char *ft_itoa(int n) { char *str; int len; int s; len = ft_nblen(n); s = ft_sign(n); if (!(str = (char *)malloc(sizeof(char) * (len + s + 1)))) return (NULL); else { str = str + len + s; *str = '\0'; if (n == 0) *--str = 48; while (n) { *--str = ft_abs(n % 10) + 48; n = n / 10; } if (s) *--str = '-'; } return (str); }
int ft_atoi(const char *s) { int sign; int i; sign = 1; i = 0; while (s[i] == '\n' || s[i] == '\v' || s[i] == '\t' || s[i] == '\r' || s[i] == '\f' || s[i] == ' ') i++; if (!(s[i] >= '0' && s[i] <= '9') && s[i] != '-' && s[i] != '+') return (0); if (ft_isdigit(s[i])) return (ft_sign(s, i, sign)); if (s[i] == '+' && ft_isdigit(s[i + 1])) return (ft_sign(s, (i + 1), sign)); if (s[i] == '-' && ft_isdigit(s[i + 1])) { sign = -1; return (ft_sign(s, (i + 1), sign)); } return (0); }