c - for-loop left after one iteration -
i'm encountering problem , don't why. used exact same loop before test (without inside code) , worked. i'm not programming newbie (though c newbie), feel one. replaced length hard coded number, doesn't change anything. jobstatus() uses for-loop works fine. appreciated!
ps: don't mind if / else-if part. desperation move because cant find problem, know don't need last else if etc.
thanks in advance
#include <stdio.h> #include <stdlib.h> short jobs[] = {6,13,7,3,4,9,10,11}; short table[13][10]; short q,i,j,k,diff; short sum; void jobstatus(short a){ printf("jobstatus:"); for(i=0;i<a;i++){ printf(" %i",jobs[i]); } printf("\n"); } int main(){ // berechne anzahl der jobs short length = sizeof(jobs)/2; printf("jobs: %i\n", length); /* für alle quanten q for(q=0;q<13;q++){ // schreibe das jeweilige quantum in die erste spalte jeder zeile table[q][0]=(q+1); gehe jeden job durch*/ for(i=0;i<length;i++){ printf("current job: %i\n", i); /* falls der aktuelle job bereits erledigt ist überspringe ihn if(jobs[i]==0){ i++; }*/ diff=jobs[i]-(q+1); if(diff>0){ jobs[i]=diff; jobstatus(length); table[q][i+1]=diff; } else if(diff==0){ jobs[i]=0; } else if(diff<0){ diff=diff*(-1); jobs[i]=0; table[q][i+1]+=diff; } } printf("# q p1 p2 p3 p4 p5 p6 p7 p8 avg.time\n"); printf("#------------------------------------\n"); for(q=0;q<13;q++){ for(i=0;i<8;i++){ printf(" %i", table[q][i]); } printf("\n"); } return 0;
}
this output:
jobs: 8 // indicates length should set 8
jobstatus: 5 13 7 3 4 9 10 11
q p1 p2 p3 p4 p5 p6 p7 p8 avg.time
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
you have global variable i
used in both loops (inside jobstatus
, in main
). once call jobstatus(length);
within main loop content of variable changed , afterwards loop terminates (because i
set length
).
Comments
Post a Comment