Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. //I have stored the entered command line in buf[1028]
  2. char *tok;
  3. tok = strtok(buf, " ");
  4. int i = 0;
  5. while(tok != NULL) {
  6. tokens[i] = malloc(sizeof(tok) + 1);
  7. strcpy(tokens[i],tok);
  8. tok = strtok(NULL, " ");
  9. i++;
  10. }
  11.  
  12. getline(cin, command);
  13. for (unsigned int i = 0; i < command.size(); i++) {
  14. if (command[i] == '"') {
  15. if (inString) {
  16. inString = false;
  17. }
  18. else {
  19. inString = true;
  20. temp += command[i];
  21. }
  22. }
  23. else {
  24. if (!inString) {
  25. if(command[i] == ' ') {
  26. toks.push_back(temp);
  27. temp = "";
  28. }
  29. else {
  30. temp += command[i];
  31. }
  32. }
  33. else {
  34. temp += command[i];
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement