This loop is not going to work:
while(q<9){
for(q=0;q<9;q++){
Once the inner loop finishes, q
is 9
, so the outer loop will finish immediately. You should use two different loop counters. I think you just meant to have
for(j=0;j<9;j++){
for(q=0;q<9;q++){
and not have g++
,j++
in the loop.