Skip to content
Snippets Groups Projects
Select Git revision
  • ae5b34d375e4ac72d8362ad954fe28cb47935e73
  • master default
2 results

utils.c

Blame
  • Forked from spring-2018-operating-systems / mysh-0
    Source project has a limited visibility.
    utils.c 661 B
    #include "utils.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    void mysh_parse_command(const char* command,
                            int *argc, char*** argv)
    {
      // TODO: Fill this!
      int i = 0;
      char *token;
      char cmd[1000];
      char seps[] = " \t\n";
    
      *argc = 0;
      *argv = (char**)malloc(sizeof(char)*15);
      (*argv)[i] = (char*)malloc(sizeof(char)*15);
    
      strcpy(cmd,command);
      token = strtok(cmd,seps);
    
      if(token == NULL){
    	  strcpy((*argv)[i],"");
    	  (*argc)++;
    	  return;
      }
    
      while(token != NULL){
    	  strcpy((*argv)[i],token);
    	  i++;
    	  (*argv)[i] = (char*)malloc(sizeof(char)*15);
    	  token = strtok(NULL,seps);
    	  (*argc)++;
      }
    }