0

Hello I have this array and I seem to forget how to naviagte through it.

Line* line = (Line*) malloc(sizeof(Line)*line_count);
for (int i = 0; i <line_count; i++){
(line + i) ->blocks = make_blocks(block_count);
(line + i) ->block_count = block_count;

}

Logic:

Line is a pointer to the start of this continuous block of memory. I want to adjust the line pointer by 1 (the size of the line) and make blocks for that specific line and set the block count.

The above (line + i) does not work I have tried line[i] (line + i)* &line[i] but still nothing

Can anyone show me the light ? Its really dark where im sitting.

Thanks

RonJermiah
  • 113
  • 1
  • 2
  • 9
  • 2
    It's more normal to use `line[i].blocks`, but `(line+i)->blocks` should work. Perhaps something else is wrong? You ought to tell us exactly what you mean by "does not work". – paddy Mar 13 '14 at 02:06
  • give us a clue as to what goes wrong. This code is basically correct – pm100 Mar 25 '14 at 20:30

1 Answers1

1

The pointer is of the type Line. You can´t point to blocks like that.

For that you would need to have an array of pointers to type blocks (if that´s a type/struct you made).

fdbva
  • 88
  • 1
  • 6