Skip to content
Snippets Groups Projects
Commit 31965a48 authored by Jaewon Choi's avatar Jaewon Choi
Browse files

Implements mysh_parse_command()

parent 24a54828
No related branches found
No related tags found
No related merge requests found
#include "utils.h"
#include <stdlib.h>
#include <string.h>
void mysh_parse_command(const char* command,
int *argc, char*** argv)
{
// TODO: Fill this!
const int kMaxArgc = 512;
*argv = (char**)malloc(kMaxArgc);
char buf[4096];
strcpy(buf, command);
char *tok = strtok(buf, " \n\t");
int ti = 0;
while (tok != NULL) {
(*argv)[ti] = (char*)malloc(strlen(tok));
strcpy((*argv)[ti], tok);
++ti;
tok = strtok(NULL, " \n\t");
}
*argc = ti;
if (*argc == 0) {
*argc = 1;
(*argv)[0] = (char*)malloc(1);
(*argv)[0][0] = '\0';
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment