我想分配内存指针结构数组,但它给了我一个奇怪的错误。下面的代码:错误分配指针数组结构
struct command{
int type;
char* input;
char* output;
struct command *command[2];
}
当我尝试了数组大小2分配内存时,我尝试:
temp->command = (command*)malloc(sizeof(struct command[2]));
不过,我得到这个错误:
incompatible types when assigning to type âstruct command *[2]â from type âstruct command *â
什么建议吗?
'temp-> command [0] = ...'和'temp-> command [1] = ...' –
'command'成员不是指向结构数组的指针,它是一个数组两个指向结构的指针。 –
你想做什么?创建一个2元素的命令数组或者一个2元素的指向数组的指针?在任何情况下,为了使malloc满足当前结构定义,您需要像这样进行演员制作:(command **) –