All pastes #1892235 Raw Edit

parse example

public text v1 · immutable
#1892235 ·published 2010-06-30 03:10 UTC
rendered paste body
import "ecere"

class prog : Application
{
   void Main()
   {
      char * source_file;
      char * tokens[20];
      source_file = CopyString("super \"man\" rides again!");
      PARSE(source_file, tokens);
      //PrintLn(tokens[3], tokens[2], tokens[1], tokens[0]);
   }

   int SCAN_STRING(char * szcheck, char * szlook)
   {
      int total, count, scan;
      char check, look;

      total = 0;
      for (count = 0; look = szlook[count]; count++)
         for (scan = 0; check = szcheck[scan]; scan++)
            if(check == look) total++;// if the search characters match characters in 
                                      // the original string... 
      return total;
   }

   int LENGTH(char * szcheck)
   { 
      int total = 0; 
      while(szcheck[++total]); 
      return total; 
   }

   int PARSE(char * parse_this, char ** tokens)
   {
      int total, count;
      char * temp_token = new char[1024];
      char cur_char;
      int len;

      total = 0;
      temp_token = CopyString("");

      for (count = 0; cur_char = parse_this[count]; count++)
      {
         if (cur_char != ' ')
         {
            temp_token[len++] = cur_char;
            PrintLn(cur_char);
            //PrintLn(temp_token);
            
         }
         else
         {
            temp_token[len] = '\0';
            PrintLn(temp_token);
            len = 0;
            tokens[total++] = CopyString(temp_token);
            temp_token = CopyString("");
         }
      }
      tokens[total]=CopyString(temp_token);
      delete temp_token;
      return total;
   }

}