Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //I have stored the entered command line in buf[1028]
- char *tok;
- tok = strtok(buf, " ");
- int i = 0;
- while(tok != NULL) {
- tokens[i] = malloc(sizeof(tok) + 1);
- strcpy(tokens[i],tok);
- tok = strtok(NULL, " ");
- i++;
- }
- getline(cin, command);
- for (unsigned int i = 0; i < command.size(); i++) {
- if (command[i] == '"') {
- if (inString) {
- inString = false;
- }
- else {
- inString = true;
- temp += command[i];
- }
- }
- else {
- if (!inString) {
- if(command[i] == ' ') {
- toks.push_back(temp);
- temp = "";
- }
- else {
- temp += command[i];
- }
- }
- else {
- temp += command[i];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement