Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;错误:请求转换为非标量类型";使用结构和malloc时_C_Struct_Malloc - Fatal编程技术网

&引用;错误:请求转换为非标量类型";使用结构和malloc时

&引用;错误:请求转换为非标量类型";使用结构和malloc时,c,struct,malloc,C,Struct,Malloc,我已经有这个问题几个小时了,并且已经把它精确到了这个简单的代码位。有人能给我一些见解吗 typedef struct test{ //I get an error regardless of what's in here }TESTS; int main(){ TESTS thing = (TESTS)malloc(sizeof(TESTS)); } malloc返回指向已分配内存的指针,您需要将其分配给测试*: TESTS* thing = malloc(sizeof(TE

我已经有这个问题几个小时了,并且已经把它精确到了这个简单的代码位。有人能给我一些见解吗

typedef struct test{
    //I get an error regardless of what's in here
}TESTS;

int main(){
    TESTS thing = (TESTS)malloc(sizeof(TESTS));
}

malloc
返回指向已分配内存的指针,您需要将其分配给
测试*

TESTS* thing = malloc(sizeof(TESTS)); 

malloc
返回指向已分配内存的指针,您需要将其分配给
测试*

TESTS* thing = malloc(sizeof(TESTS)); 

怎样。我怎么会花这么多时间在这么简单的事情上,我真的已经知道了。谢谢。:)发生在我们所有人身上。很高兴我能帮忙!最好完全移除铸件。@R..-脱模。我的C是生锈的,不记得首选的成语。我怎么会花这么多时间在这么简单的事情上,我真的已经知道了。谢谢。:)发生在我们所有人身上。很高兴我能帮忙!最好完全移除铸件。@R..-脱模。我的C是生锈的,不记得首选的成语。