One dimensional array

I have to use one dimensional array as 2d matrix of some values.
The problem is that i need to check if given index is out of bounds on the right side (column) border.
Since i can come up with solution i have tried google but none of the answers is to be found.

Thank you for your time.
Wait. You have both max X size and max Y size (for subscript transition between 2D<=>1D)
What problem do you have?
wat is ur criteria for assigning memory for 2d array ??? if that is clear then ur problem is solved.
I have a 7x7 matrix which of inner 5x5 fields are "valid", i need to check if some given index is out of that bounds (specially on the right side column).


Am i clear now? Sorry for bad enlish.

Thank you for your time.
Last edited on
do u know the col no of element u are checking?
Last edited on
if (x > 0 && x < 6 && y > 0 && y < 6)?

do u know the col no of element u are checking?

Yes, rightmost column.

@MiiNiPaa
I know that but i need to check only the rightmost column.
Please don't ask why. :D

1
2
3
//looping of 2D array
if(y == 6)
//ur action 
Last edited on
But looping thru 1D array (as 2D), touching only rightmost column. I have that limitation, otherwise it would be easy.
Last edited on
If you are using 1D array as 2D, you have some way to map 2D coordinates to 1D, right?
I think this is it?
1
2
3
4
5
for (i = 0; i < 7; ++i)
    //for (j = 7; j < 7; ++j)
    j = 6;
    inx = i * 6 + j;
    array[inx]


If it is i am uber stupid.
1
2
    j = 6;
    inx = i * 6 + j;

Either i * 7 (if valid indexes is 0..6) or j = 5 (if they are 0..5)
Thank you all.
Topic archived. No new replies allowed.