Advertisement
ZoriaRPG

atoi.zh

Jul 17th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. ffc script atoi
  2. {
  3.     void run(){}
  4.    
  5.     int parse(int ptr)
  6.     {
  7.         int buffer[100];
  8.         int q = -1; int w;
  9.         do
  10.         {
  11.             ++q;
  12.         } while(!isnumber(ptr[q]);
  13.         //Add sign.
  14.         if ( ptr[pos-1] == '-' )
  15.         {
  16.             buffer[0] = '-';
  17.             ++w;
  18.         }
  19.         while(isnumber(ptr[q])
  20.         {
  21.             buffer[w] = ptr[q];
  22.             +=w;
  23.         }
  24.         return atoi(buffer,0);
  25.     }
  26.     int parse(int ptr, int pos)
  27.     {
  28.         bool neg;
  29.         int buffer[100];
  30.         --pos;
  31.         int w;
  32.         do
  33.         {
  34.             ++pos;
  35.         } while(!isnumber(ptr[pos]);
  36.         //Add sign.
  37.         if ( ptr[pos-1] == '-' )
  38.         {
  39.             buffer[0] = '-';
  40.             ++w;
  41.         }
  42.         while(isnumber(ptr[pos])
  43.         {
  44.             buffer[w] = ptr[pos];
  45.             ++w;
  46.         }
  47.         return atoi(buffer,0);
  48.     }
  49.     bool isnumber(int chr)
  50.     {
  51.         if ( chr >= '0' )
  52.         {
  53.             if ( chr <= '9' ) return true;
  54.         }
  55.         return false;
  56.     }
  57.     int get(int string, int pos)
  58.     {
  59.         int i=0;
  60.         bool neg = false;
  61.         if(string[pos + i] == '-'){
  62.             ++i;
  63.             neg = true;
  64.         }
  65.         int ret;
  66.         for(ret = 0; isNumber(string[pos + i]); ++i)
  67.             ret = ret*10 + (string[pos + i] - '0');
  68.         return ret*Cond(neg, -1, 1);
  69.     }
  70.     int get(int string)
  71.     {
  72.         return atoi(string, 0);
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement