int parse_command_line (char commandLine[MAX_INPUT_LINE_LENGTH], char* cmds[MAX_CMDS_NUM]){
char delims[] = "|";
char *result = NULL;
result = strtok(commandLine, delims);
int count = 0;
if((logfp=fopen("LOGFILE", "w"))==NULL)
{
perror("Error");
exit(1);
while(result != NULL) {
fprintf(logfp, "cmd[%d] will point to string \"%s\"\n", count, result);
count=count+1;
result = strtok(NULL, delims);
}
fclose(logfp);
//exit(1);
}
fprintf語句使行終止於delim「|」進入LOGFILE。我希望該值也可以存儲在一個數組中,我可以在後面的過程中訪問它。每次將一行添加到LOGFILE時,我都需要該值在數組中。如何獲取打印到LOGFILE的值以存儲在陣列中
cmd是,它需要被存儲在陣列..我的理解是它未尚未初始化。我該如何初始化cmd作爲一個數組,可以保存每行,因爲函數遍歷命令行輸入來解析它們 – user2112062 2013-03-21 15:15:09