#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char **read_command(char *text) {
    int index=0;
    char **res=NULL;
    char *command= malloc(strlen(text)+1);
    strcpy(command, text);
    char *tok = strtok(command, " ");
    while(tok!=NULL) {
        res = realloc(res, sizeof(char*)*(index+1));
        char *dup = malloc(strlen(tok)+1);
        strcpy(dup, tok);
        res[index++] = dup;
        tok = strtok(NULL, " ");
    }
    res[index++]=NULL;
    free(command);
    return res;
}

int main(void) {
	char *input="read A B C";
    char **command = read_command(input);
    for (int i = 0 ; command[i] ; i++) {
    	printf("'%s'\n", command[i]);
    }
	return 0;
}
