我想將一個命令的指針存儲到二維數組中。下面是我正在使用的一些代碼,但我不知道如何得到想要的結果。如何將指針存儲到我的2d數組中?
#define MAX_LINE_LENGTH 1024
#define MAX_COMMANDS 10
char *commandHistory[MAX_COMMANDS][MAX_LINE_LENGTH + 1];
char *token;
token = strtok(line, LSH_TOK_DELIM);
printf("%s\n", token); //prints out the command I want to store the pointer to
commandHistory[i++][0] = token; //what do I do here?
爲什麼你分裂線?只要'commandHistory [i ++] = strdup(line);' –