Please support our C++ advertiser: Programming Forums
![]() |
•
•
Join Date: Jun 2008
Posts: 16
Reputation:
Rep Power: 1
Solved Threads: 0
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...
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...
Last edited by zourlas : Jul 25th, 2008 at 7:34 am.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,861
Reputation:
Rep Power: 40
Solved Threads: 1012
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
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;
}
}
}•
•
Join Date: Jun 2008
Posts: 16
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
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;
}
}}![]() |
Similar Threads
Other Threads in the C++ Forum
- Super-power compare method? <?> (Java)
- need info? can't use strcmp/string compare (C++)
- Comparing arrays (C++)
- compare (C++)
- Comparing elements of two seperate Arrays (PHP)
- Need Help Outputting Information Using Arrays In QBasic (Legacy and Other Languages)
- creating random immutable numbers (Visual Basic 4 / 5 / 6)
- sorting 2d arrays (C)
Other Threads in the C++ Forum
- Previous Thread: converting file types
- Next Thread: Is this book good?
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode