【发布时间】:2014-10-15 12:26:50
【问题描述】:
我正在尝试使用另一个指针将结构分配给指针
typedef struct cat Category;
Category{
///some stuff here
};
Category *categoryList;
Category *ap = &categoryList;
*ap = (Category *)malloc(sizeof(Category));
我明白了:
error: incompatible types when assigning to type 'Category' from type 'struct Category *'
我做错了什么?
【问题讨论】:
-
需要使用ASCII解法
-
首先:永远不要在c中强制转换malloc的返回值! ;)
-
通过 *ap 你取消引用指针...
-
(*ap) 的类型是结构类别。
-
很明显,OP 是 C 的新手。预计单个问题中会有两个或多个错误...因为当 Stack Overflow 成为专家提问的唯一场所?