How to get index of structure elements?
Hi
I want to get the starting index of structure elements, whoz id are 0,1,2,3
Like in below code
col_data[0] (starting id=0)
col_data[3] (starting id=1)
col_data[5] (starting id=2)
col_data[8] (starting id=3)
Code:
typedef struct gg{
int id;
int value;
} gg;
gg col_data[10]={{0,44},{0,46},{0,39},{1,25},{1,10},{2,46},{2,78},{2,55},{3,64},{3,79}};
int ptr[4];
for (i = 0; i < 4; i++){
for (j = 0; j < 10; j++){
if (col_data[j].id==i){
ptr[i]=j;
// If i use break it will break after first match and will not go again to the loop.
break;
}
}
}
output should be
ptr[0]=0
ptr[1]=3
ptr[2]=5
ptr[3]=8
How can i skip remaining loop iterations when it get that index and will go back to loop again for getting next element index?