SHARE
TWEET

Untitled

a guest Sep 11th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int         wrong_value(char *base, int base_len)
  2. {
  3.     int i;
  4.     int j;
  5.  
  6.     i = 0;
  7.     j = 1;
  8.     if (base_len <= 1)
  9.         return (0);
  10.     while (i <= base_len)
  11.     {
  12.         while (j <= base_len)
  13.         {
  14.             if ((base[i] == base[j]) || (base[i] == '-') || (base[i] == '+'
  15.                         || (base[i] >= 9 && base[i] <= 13) || base[i] == 32))
  16.                 return (0);
  17.             j++;
  18.         }
  19.         i++;
  20.         j = i + 1;
  21.     }
  22.     return (1);
  23. }
  24.  
  25. int         char_in_base(char stri, char *base, int baselen)
  26. {
  27.     int i;
  28.  
  29.     i = 0;
  30.     while (i < baselen)
  31.     {
  32.         if (stri == base[i])
  33.             return (1);
  34.         i++;
  35.     }
  36.     return (0);
  37. }
  38.  
  39. int         base_len(char *base)
  40. {
  41.     int i;
  42.  
  43.     i = 0;
  44.     while (base[i])
  45.     {
  46.         i++;
  47.     }
  48.     return (i);
  49. }
  50.  
  51. int         position_in_base(char stri, char *base)
  52. {
  53.     int j;
  54.  
  55.     j = 0;
  56.     while (base[j])
  57.     {
  58.         if (base[j] == stri)
  59.             return (j);
  60.         j++;
  61.     }
  62.     return (0);
  63. }
  64.  
  65. int         ft_atoi_base(char *str, char *base)
  66. {
  67.     int         i;
  68.     int         moins;
  69.     long int    conv;
  70.     long int    baselen;
  71.  
  72.     baselen = base_len(base);
  73.     if (wrong_value(base, baselen) == 0)
  74.         return (0);
  75.     conv = 0;
  76.     i = 0;
  77.     moins = 1;
  78.     while ((str[i] >= 9 && str[i] <= 12) || str[i] == 32)
  79.         i++;
  80.     while (str[i] == 43 || str[i] == 45)
  81.     {
  82.         if (str[i] == 45)
  83.             moins = -moins;
  84.         i++;
  85.     }
  86.     while (char_in_base(str[i], base, baselen) == 1)
  87.     {
  88.         conv = conv * baselen + position_in_base(str[i], base);
  89.         i++;
  90.     }
  91.     return (conv * moins);
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top