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 添加一行时,我都需要在数组中添加该值。
最佳答案
要做的,只需添加
cmds[count] = result;
在fprintf()
之后和count=count+1;
之前
关于c - 如何将打印到 LOGFILE 的值存储在数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15551261/