Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. void semiTokenizer (char *token, char *string)
  5. {
  6.     int i = 0, ti = 0;
  7.     int y;
  8.     //remove spaces before first token...
  9.     while ( string[i] == ' ' )
  10.         i++;
  11.  
  12.     //get first token...
  13.     while ( string[i] != ' ' && string[i] != '\0' )
  14.     {
  15.         if ( string[i] == '"' ) {
  16.             for ( i = i + 1 ; string[i] != '\0'  ; i++ ) {
  17.                 if( string[i] == '"' && (string[i + 1] == ' ' || string[i + 1] == '\0') ) {
  18.                     i++;
  19.                     break;
  20.                 }
  21.                 token[ti++] = string[i];
  22.             }
  23.         } else {
  24.             token[ti++] = string[i];
  25.             i++;
  26.         }
  27.     }
  28.     token[ti] = '\0';
  29.  
  30.     //remove "token" from original string...
  31.     y = 0;
  32.     while ( i < (strlen(string) + 1) ) {
  33.         string[y++] = string[i++];
  34.     }
  35. }
  36.  
  37. int main(void)
  38. {
  39.     char commandline[100];
  40.     char tuken[25];
  41.     int i = 0;
  42.  
  43.     gets(commandline);
  44.  
  45.     do {
  46.         semiTokenizer(tuken, commandline);
  47.         cout <<  tuken << endl;
  48.     } while ( strlen(tuken) );
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement