2013-11-27 300 views
1

我目前正试图分配一个指向名为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; 
+1

'righthead = current-> right;'should be'righthead = currect-> right;' –

回答

1

领域right在结构rect不应有struct之前totherightstruct _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; 
+0

解决了我的问题!我不能相信我错过了这一点。谢谢,迈克尔! – Cody