eg0rmaffin

this atoi is actually works!

Sep 12th, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. int     ft_atoi(char *str)
  2. {
  3.     int     sign;
  4.     size_t  res;
  5.  
  6.     sign = 1;
  7.     res = 0;
  8.     while (((*str > 8) && (*str < 14)) || (*str == 32))
  9.         str++;
  10.     if (*str == '-' || *str == '+')
  11.     {
  12.         if (*str == '-')
  13.             sign = -1;
  14.         str++;
  15.     }
  16.     while ((*str >= '0') && (*str <= '9'))
  17.     {
  18.         if (res <= 9223372036854775807)
  19.             res = (res * 10) + (*str - '0');
  20.         else if (sign == -1)
  21.             return (0);
  22.         else
  23.             return (-1);
  24.         str++;
  25.     }
  26.     return (res * sign);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment