Note that there are some explanatory texts on larger screens.

plurals
  1. POfor-loop left after one iteration
    primarykey
    data
    text
    <p>I'm encountering this problem and I don't get why. I used the exact same loop before to test it (without inside code) and it worked. I'm not a programming newbie (though c newbie), but now I definitely feel like one. I replaced length with a hard coded number, doesn't change anything. jobStatus() also only uses a for-loop which works fine. Help is appreciated!</p> <p>PS: Don't mind the if / else-if part. This was just a desperation move because I cant find the problem, I know that I don't need the last else if etc.</p> <p>thanks in advance</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; 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&lt;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&lt;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&lt;length;i++){ printf("Current Job: %i\n", i); /* falls der aktuelle job i bereits erledigt ist überspringe ihn if(jobs[i]==0){ i++; }*/ diff=jobs[i]-(Q+1); if(diff&gt;0){ jobs[i]=diff; jobStatus(length); table[Q][i+1]=diff; } else if(diff==0){ jobs[i]=0; } else if(diff&lt;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&lt;13;Q++){ for(i=0;i&lt;8;i++){ printf(" %i", table[Q][i]); } printf("\n"); } return 0; </code></pre> <p>}</p> <p>This is the output:</p> <p>Jobs: 8 // Indicates that length should be set to 8</p> <p>Jobstatus: 5 13 7 3 4 9 10 11</p> <h2> Q P1 P2 P3 P4 P5 P6 P7 P8 Avg.Time</h2> <p>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</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload