我将使用两组char*(或字符串)读取strtok,并且因为这两组字符是相关的,(address : command\n)所以我决定使用一个结构.
struct line* array = (struct line*)malloc(sizeof(file) * sizeof(struct line*));
Run Code Online (Sandbox Code Playgroud)
这个malloc函数的行间空间给了我一个分段错误,并想知道你是否可以告诉我一个适当的malloc空间方式.对于上下文,这是我的其余代码:
struct line
{
char* addr;
char* inst;
};
while loop{
x = strtok(line,": ");
y = strtok(NULL,"\n");
strcpy(array[i].addr,x); //assume that x and y are always 3characters
strcpy(array[i].inst,++y);
i++;
}
Run Code Online (Sandbox Code Playgroud)