評價: 0 回應: 0 閱覽: 65
置頂

如何存取struct 成員變數

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

struct C
{
    int num;
    char *str;
};
struct B
{
    struct C *c;
};


typedef struct A
{
    struct B *b;
}t_A;



int main()
{
    t_A *a=(t_A *)malloc(sizeof(t_A));

    a->b->c.num=5;
    printf("%d",a->b->c.num);

    //a->b->c->str="test";
    //printf("%s",a->b->c->str);

    system("pause");
    return 0;
}

請問一下 要如何改 才能使用num and str這二個變數@@?


如果宣告成 t_A a1;

a1.b->c.num=5;  這是我的理解@@...

雖然編譯是錯的...

 

 

基本上 只要是*a

我就想成 a要指到下一個位址, 然後又是*號的話 又會指到下一個位址...

 

請問一下 這要何解@@

會員登入 (先登入會員才能回覆留言喔!)

Facebook留言