为什么我不能通过它的指针访问这个结构?

Pie*_*ter 1 c malloc struct pointers operators

#include <stdio.h>
#include <stdlib.h>

typedef int element;

struct cell {
    element e;
    struct cell *p;
};
typedef struct cell* CELL;

int main() {
    CELL* p;
    p = (CELL*) malloc (sizeof(struct cell));
    p->e = 8;       /* This ain't working */
    *p.e = 8;       /* This doesn't help anything either */

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我刚刚开始使用malloc,我刚刚创建了一个指向新创建的指针CELL,这是一个struct.现在我正试图用一些值来填充它,但是我在一个不是结构或联合的东西中对一个不友好的"成员e的请求"表示欢迎.我确实指向一个struct包含一个名为e的成员的指针,或者至少那是我的想法.为什么这会失败?

小智 9

我认为这很好地说明了一个好的C风格规则 - 不要创建隐藏事物是指针的事实的typedef.


cod*_*ict 6

更改

cel* p;
p = (CELL*) malloc (sizeof(struct cell));

*p.e = 8;
Run Code Online (Sandbox Code Playgroud)

struct cell* p; // or CELL p;
p = (CELL) malloc (sizeof(struct cell));

(*p).e = 8; // . has higher precedence than *
Run Code Online (Sandbox Code Playgroud)