1

I have a struct in struct array inside another struct array and need to access values in this struct.

typedef struct unit
{
    bool isNot;
    char letter;
} unit;

typedef struct line
{
    unit *clause;
    int lineLength;      
} line;

typedef struct fullData
{
    line **table;
} fullData;

I am trying to access a unit struct i have created like so:

struct fullData Block;
struct Line lines;

and then to access:

 Block.table[i][j].letter 

to get the letter in the unit struct.

This is kinda abridged, but the 2d array is massively populated.

4
  • 1
    Seems to me you have to do something like Block.table[i][j].clause[z].letter where z is the unit index you are trying to access. Commented Apr 25, 2020 at 2:34
  • @AndréSantos because its only a 2d array, would it be Block.table[i].clause[j] ? Commented Apr 25, 2020 at 2:39
  • Oh, if table it's a simple array of pointers it would be Block.table[i]->clause->letter then. table[i] is a line * so you dereference it with -> to get a line. Same logic for clause, which is a unit * and you have to dereference using the ->. Commented Apr 25, 2020 at 2:51
  • You hit the nail on the head of what i'm trying to. Ill make those changes now, thanks so much! Commented Apr 25, 2020 at 2:51

1 Answer 1

2

If I understand you correctly, I think you are trying to store letters in each cell of a table. Make the line **table as line *table. Then you can use Block->table[i]->clause[j]->letter to access letter at i and j. This makes more sense as a table is an array of lines and a line is an array of letters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.