-2

I'm currently facing some problems accessing a double pointer. 1. The double pointer that is an element of a structure. 2. The double pointer is also instance of another structure. 3. That structure also contains an element that is explicitly a char type variable declared by typedef.

For example. The main structure is this.

typedef struct SomeOne
{
    NodeT **aOthers;
    int   height;
} SomeOne;

NodeT is defined as below:

typedef struct NodeT
{
    NodeItemT info;
} NodeT;

NodeItemT is defined as below:

typedef char NodeItemT;

Now from the main function I want to add a value to the

NodeT **aOthers;

I have to declare SomeOne structure as follow:

SomeOne* somePerson;

Now from somePerson if I've to store a value to the "**aOthers" what I've to do? To add a value I've a function defined as this:

void padd(SomeOne *somePerson, NodeItemT item);

Now can anyone please help me to define this function?

  • 1
    Welcome to Stack Overflow! Please show your research/debugging effort so far. Please read [Ask] page first. – Sourav Ghosh Sep 06 '16 at 08:07
  • 6
    `C` != `C++`, choose one. – Sourav Ghosh Sep 06 '16 at 08:07
  • _There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs._ – Sourav Ghosh Sep 06 '16 at 08:07
  • 1
    What are your thoughts on how this function should work? Stackoverflow won't do the thinking for you. When you have specific questions we help but we won't write functions for you (especially not those kind of functions which are for learning). Also: it is better to post your code in one block, in a way people can copy+paste it to test things. – Hayt Sep 06 '16 at 08:08
  • The data design seems odd. I don't understand the `aOthers` member. It is not clear to me how it is supposed to be used. – Klas Lindbäck Sep 06 '16 at 08:22

1 Answers1

1

Here are your types:

typedef char NodeItemT;
typedef struct
{
    NodeItemT info;
} NodeT;
typedef struct
{
    NodeT **aOthers;
} SomeOne;

Here's how you can access them:

SomeOne so;
NodeT* others = new NodeT();
so.aOthers = &others;
(*so.aOthers)->info = 'A';

Does aOthers have to be a pointer to a pointer?

Ivan Rubinson
  • 3,001
  • 4
  • 19
  • 48