Thread: Loop doesnt continously execute

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User spendotw's Avatar
    Join Date
    Dec 2011
    Location
    England
    Posts
    40

    Question Loop doesnt continously execute

    Hi there i am writting a process scheduler and im confused at this point in my code below....

    When i compile the program, it compiles successfully and decrements the structure member qaunta by -1 continously. But what i want it to do is to decrement the qaunta variable by -1 and then print that variable and move onto the next variable do the same to that one and keep going round until qaunta reaches the value of 0 (round robin fashion). Thanks
    Code:
    int comp(const void *a, const void *b) {
        return ((struct process*)a)->priority - ((struct process*)b)->priority;
    }
    
    /* order the priority in the correct order */
        qsort(proc, 199, sizeof(*proc), comp);
    
    } 
    /* Decrement the process qaunta */ 
    for ( i = 0; i < 199; i++ ) {
        printf("%s %d %d\n", proc[i].id, proc[i].qaunta, proc[i].priority);
        while (proc[i].qaunta != 0 ) {        
            proc[i].qaunta = proc[i].qaunta - 1;
                printf("%s Qaunta: %d \n",proc[i].id, proc[i].qaunta);
                 if (proc[i].qaunta == 0 )
                    printf("Goodbye\n");
                }
    Heres the end of my output (its continous throughout):
    Process10 Qaunta: 150
    ..................................
    Process10 Qaunta: 0
    Last edited by spendotw; 01-04-2012 at 07:42 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using the while loop to execute sequences
    By jamesallen4u in forum C Programming
    Replies: 15
    Last Post: 10-03-2011, 04:42 AM
  2. why the first loop doesnt stop..
    By transgalactic2 in forum C Programming
    Replies: 1
    Last Post: 06-20-2009, 07:07 AM
  3. why this while condition doesnt stop the loop??
    By transgalactic2 in forum C Programming
    Replies: 40
    Last Post: 04-07-2009, 08:38 AM
  4. My loop doesnt work
    By Evandb in forum C Programming
    Replies: 3
    Last Post: 05-17-2004, 11:04 PM
  5. doesnt work while ..loop
    By condorx in forum C Programming
    Replies: 3
    Last Post: 02-24-2002, 12:53 PM

Tags for this Thread