我目前正在尝试将指针分配给一个名为 totheright 的结构(这是一个链表节点)。指向结构/列表的指针当前位于另一个称为矩形的结构中。我在尝试这样做时遇到错误。
currect->right = malloc(sizeof(totheright));
righthead = current->right;
以下是函数中的声明:
rect *currect = NULL;
totheright *righthead = NULL;
标题中的结构定义:
typedef struct _totheright {
int rect;
struct _totheright *right;
} totheright;
typedef struct _rect {
int thisrect;
struct totheright *right;
int left;
double width;
double height;
double xcord;
double ycord;
struct _rect *next;
} rect;
最佳答案
字段 right
在结构中rect
不应该有 struct
之前 totheright
或 struct _totheright
应该使用:
typedef struct _rect {
int thisrect;
//struct totheright *right; // was
totheright *right; // fixed
//struct _totheright *right; // that would be ok as well
int left;
double width;
double height;
double xcord;
double ycord;
struct _rect *next;
} rect;
关于c - 从不同结构类型中的指针向结构指针赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20244440/