Originally Posted by
Daved
Sorry, just noticed you already answered that, but it doesn't exactly match your initial post.
I assume that the values that are not set are already defaulted to some number (like 0 or -1) that cannot be an actual value for the id.
If that is the case, then for each id, you'd start at tmp[0][0]. If it matches, then you loop through tmp[0][j] until it is not used (it has that initial value 0 or -1) and then place it there. If tmp[0][0] doesn't match, you move on to tmp[1][0] and repeat. Continue until tmp[i][0] has the inital value (0 or -1), meaning it hasn't been used yet. At that point set it to the current value.
That algorithm can be done in two simple loops, where you have a done variable that allows you to break out of the two loops when you actually findthe right location. A third loop can be used to cycle through the a array.
i wrote it but something is working incorrectly it stores again at diff locations
here is the code
y is size of STORE1
Code:
tmp[0][0].custnum = STORE1[0].custnum;
for(int j=1;j<y;j++) {
for(int k=0;k<row;k++) {
if(STORE1[j].custnum == tmp[k][0].custnum) {
for(int i=0;i<col;i++) {
if(tmp[k][i].custnum == 0) {
tmp[k][i].custnum = STORE1[j].custnum;
break;
}
if(tmp[k][0].custnum == 0) {
tmp[k][0].custnum = STORE1[j].custnum;
break;
}
}
}
}
}
here is the output
Code:
[0][0]:10212
[0][1]:10212
[0][2]:10212
[0][3]:0
[0][4]:0
[1][0]:13114
[1][1]:0
[1][2]:0
[1][3]:0
[1][4]:0
[2][0]:11234
[2][1]:0
[2][2]:0
[2][3]:0
[2][4]:0
[3][0]:10212
[3][1]:10212
[3][2]:0
[3][3]:0
[3][4]:0
[4][0]:10212
[4][1]:0
[4][2]:0
[4][3]:0
[4][4]:0