Two problems that I can notice in your code if(ptr[x][y] == OK)
(1):
ptr is a pointer to a structure (single *), you cannot use double indices [][] , so the error is in if(ptr[x][y] == OK)
error, indexed value is neither an array nor a pointer due to ptr[][]
(2):
error: a structure type value is used where a scalar is required means if(struct are not allow) .
if(should be a scalar value )
The value of the scalar value can be converted to 0/1.
Pointer to an array of 2D structure C
struct structX matrix2D[ROW][COL];
pointer
struct structX (*ptr2D)[ROW][COL]; ptr2D = &matrix2D;
ok, access the array structure as follows:
struct structX i; (*ptr2D)[r][c] = i;
If you want to pass a function, follow these steps:
void to(struct structX* ptr2D[][COL]){ struct structX i; ptr2D[][COL] = i; } void from(){ struct structX matrix2D[ROW][COL]; to(matrix2D); }
Just to make sure that I wrote a simple code, it shows how to work with ptr2D . Hope you find it helpful:
#include<stdio.h>
And his work, output:
5 a in to: 5 a
EDIT
I wanted to show two tricks, but now I think that I should provide a single method (as you commented): So, here is the code:
#include<stdio.h>
Output
5 a in to: 5 a
EDIT :
error: a structure type value is used where a scalar is required means if(struct are not allow) .
if(should be a scalar value )
you cannot do like if((*ptr2D)[r][c]);
but it allows you to:
if((*ptr2D)[r][c].a == 5);
or
if((*ptr2D)[r][c].b == 'a');
or
if((*ptr2D)[r][c].a == 5 && (*ptr2D)[r][c].b == 'a');
or
structX i; if((*ptr2D)[r][c] == i);