String Parsing

#include <sstream>
#include <string.h>
#include <stdio.h>

char gstr[] = "M 0,320 L 0,0 L 240,0 L 480,0 L 480,320 L 480,640 L 240,640 L 0,640 L 0,320 z";
char seps[]   = " ,\t\n";
char *token;

int parsing2( void )
{
   printf( "Tokens:\n" );
 
   // Establish string and get the first token:
   token = strtok( gstr, seps ); // C4996
   // Note: strtok is deprecated; consider using strtok_s instead
   while( token != NULL )
   {
      // While there are tokens in "string"
      printf( " %s\n", token );

      // Get next token: 
      token = strtok( NULL, seps ); // C4996
   }

   return 0;
}

int parsing1()
{
        std::string a;
        int x, y;
        std::stringstream s(gstr, std::ios::in);
        
        int curMode = 0;
        while (! s.eof())
        {
                s >> a;
        }
        return 0;
}

int main(int argc, _TCHAR* argv[])
{
        parsing2();

        return 0;
}


Back