I can't answer all your questions, but when you work with 8 pairs from 'idx' 0 to 7, then your for-loop should be: for(i=0; i<8; i++)