looping prob for loop

This is a discussion on looping prob for loop within the C Programming forums, part of the General Programming Boards category; Hey guys in this function my for loop is stuffin up its goin in a neverending loop for some reason? ...

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    looping prob for loop

    Hey guys in this function my for loop is stuffin up its goin in a neverending loop for some reason?




    Code:
    void totalDays(unsigned month, unsigned year, int ar[])
    {
       /*int i;
       
        print out the array in main the months
       for(i=0; i<MAX_MONTH; i++)
       {
       printf("days array hello:%d\n", ar[i]);
       } */
       
       
       int i;
       int md=0;
       int leap=0;
       int startYear = 1900;
       int track;
       unsigned int d, yrd;
       
       /* starts from 1900 goes to the input year*/
       for(i=startYear; i<year; i++) 
       {
           /* check if that year is a leap year*/
           if((i%4==0)&&((i%100!=0) || (i%400==0)))
           {
               leap++;  /* add exstra day*/
    	   
           }
       } 
       
       for(i=0; i<(month-1)&&(i<11); i++)
       {
               md=md+ar[i]; 
    	   yrd = (year-startYear)*365;
               d=yrd+leap+md;
    	   
               track=d%7;
       }   
               printf("ello%d\n", month);
    	   displayCalendar(month, year, ar, &track);
       
       
       
      /* return ar[i] ;*/
    }

  2. #2
    Registered User
    Join Date
    Mar 2006
    Posts
    9
    Hey there,

    Did not spot an endless loop with a debug, maybe you input year as yy? Like '98' instead of '1998'?

    greetz

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Perhaps the infinite loop is in displayCalendar().
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Deal or No Deal listbox prob
    By kryptkat in forum Windows Programming
    Replies: 5
    Last Post: 03-30-2009, 06:53 PM
  2. wierd looping effect after exporting 3ds to .x annimation
    By Anddos in forum Game Programming
    Replies: 3
    Last Post: 01-06-2009, 12:43 PM
  3. problems with prototype function looping
    By dezz101 in forum C Programming
    Replies: 5
    Last Post: 04-29-2008, 06:03 AM
  4. looping went berserk
    By miryellis in forum C Programming
    Replies: 7
    Last Post: 09-21-2004, 01:59 PM
  5. Looping questions
    By Peyote in forum C++ Programming
    Replies: 3
    Last Post: 09-15-2003, 11:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21