Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. int     ft_is_digit(char c)
  2. {
  3.     if (c >= '0' && c <= '9')
  4.     {
  5.         return (1);
  6.     }
  7.     return (0);
  8. }
  9.  
  10. int     ft_is_whitespace(char *str)
  11. {
  12.     if (*str == ' ' || *str == '\t' || *str == '\n' || *str == '\r')
  13.     {
  14.         return (1);
  15.     }
  16.     return (0);
  17. }
  18.  
  19. int     ft_atoi(char *str)
  20. {
  21.     int     result;
  22.     int     sign;
  23.  
  24.     while (*str != '\0' && ft_is_whitespace(str))
  25.     {
  26.         str++;
  27.     }
  28.     sign = 1;
  29.     if (*str == '+')
  30.     {
  31.         str++;
  32.     }
  33.     else if (*str == '-')
  34.     {
  35.         sign = -1;
  36.         str++;
  37.     }
  38.     result = 0;
  39.     while (ft_is_digit(*str) && *str != '\0')
  40.     {
  41.         result *= 10;
  42.         result = result + *str - '0';
  43.         str++;
  44.     }
  45.     return (result * sign);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement