Posted by Fox on 2000-04-30
> char Matrix[5][5]; /*Filled with letters*/
>
> /*I have variables containing letters*/
> char Ch1, Ch2;
>
> Any ideas on how I can see if :-
>
> 1) Ch1 && Ch2 are in the same row of the Matrix;
> 2) Ch1 && Ch2 are in the same column of the Matrix,
> 3) If neither of the above, do something else.
/********************************/
Easy!
int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
for(y1 = 0; y < 5; y++)
{
for(x1 = 0; x < 5; x++)
{
if(Matrix[y1][x1] == Ch1)
//do something to exit the loop, and keep the x1,y1 values in tact
}
}
for(y2 = 0; y < 5; y++)
{
for(x2 = 0; x < 5; x++)
{
if(Matrix[y2][x2] == Ch2)
//do something to exit the loop, and keep the x2,y2 values in tact
}
}
You'll end up with (x,y) coordinates for both.
The 'y' value is what row it's in, the 'x' is for the column.
If I remember right, the coordinate system for multi-dimentional arrays is like:
_x_x_x_x_x
y | C C C C C
y | C C C C C
y | C C C C C
y | C C C C C
y | C C C C C
!!Please correct me if I'm wrong!!
All you have to do is search for it until you get the target's coordinate pair; it's
location. Then do the same for your next target. The values of their respective
(x,y) pair will tell you if they're in the same row or column.
*******************************************
My brain is powered by C++
My hands are trained for the keyboard
My legs are built for the hockey floor
My ears are tuned to Mike Oldfield
My eyes are sensitive to video games
My attitude is sarcastic
My body is the work of God!
Previous post | Next post | Timeline | Home