Hello mates


I have a new question...

I have 2 2-d arrays with the same dimensions and contents.
The first one, say a [15][4] and the second on, say b[15][4] and are both char type.

They both have the same elements(same 4character Lines) but in different order(the second one's Lines are mixed compared with the first one)....

My question is,

if i declare an array, say int c [15] wht should i do to use it as an index for the array b compared to array a.
for example

i array A i array B i index array C
0 abcd 0 jklm 0 2
1 efgh 1 abcd 1 0
2 ijkl 2 efgh 2 1
. . . .
. . . .
. . . .

i don't want to change the variable type of the arrays becouse this routine is one part of big function i am currently programing.I am tring to think of a way of comparing these 2d arrays line by line and fill in the index array.

Thanks in advance...

1) are those null-terminated strings? If yes, then the first row in A would be abc, not abcd.

2) I guess C will contain the row number in B that matches the row in A?

probably something like this

const int maxrows = 15;
for(int i = 0; i < maxrows; i++)
{
    for(int j = 0; j < maxrows; j++)
    {
        if( strcmp(A[i], B[i]) == 0)
        {
            C[i] = j;
            break;
        }
    }
}

1) are those null-terminated strings? If yes, then the first row in A would be abc, not abcd.

2) I guess C will contain the row number in B that matches the row in A?

probably something like this

const int maxrows = 15;
for(int i = 0; i < maxrows; i++)
{
    for(int j = 0; j < maxrows; j++)
    {
        if( strcmp(A[i], B[i]) == 0)
        {
            C[i] = j;
            break;
        }
    }
}

that worked fine but i also tested this which stores the wanted line to a a string s.
Thanks mate +1 from me

for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
s[j]=b[i][j];

}
for (l = 0; l < 4; l++) {
for (m = 0; m < 4; m++) {
if(a[l][m]==s[m]){c[i]=l;}
else
break;
}

}}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.