distahl
distahl

Reputation: 11

How to access memebers of a reference to a reference to a struct. (struct**)

I'm very new to C programming. And I'm asking myself how I can access mebers of double referenced structs. (Not sure if you even would name it like this.)

So having this simple example:

#include  <stdio.h>
#include  <string.h>

typedef struct {
    char n[4];
} inner;
typedef struct {
    inner inner[5];
} outer;


int main(void)
{
    outer o;
    strcpy(o.inner[0].n, "123");
    strcpy(o.inner[1].n, "ABC");
    
    // Working. Prints "123".
    printf("%s\n", o.inner[0].n);
    
    outer* oo = &o;
    
    // Working. Prints "123".
    printf("%s\n", oo->inner[0].n);
    
    outer** ooo = &oo;
    
    // Not working. Need help here, please.
    printf("%s\n", *ooo->inner[0].n);
    
    return 0;
}

How can I access members of outer** ooo. I tried something in the last printf statement, but is not working.

Upvotes: 0

Views: 49

Answers (1)

distahl
distahl

Reputation: 11

Thanks to @Ted Lyngmo and @Ian Abbott. The correct answers are:

(*ooo)->inner[0].n

or

ooo[0]->inner[0].n

Upvotes: 1

Related Questions