ctime.hctime

When I use ctime my loop runs half the amount of times as it should


The size is defined as 15, but this program only runs 8 times for some reason and i don't know why. This part is the only issue. Once i removed it and replaced it with something that doesn't use ctime it ran 15 times.

    for(int count = 0; count < size; count++) 
    {
        printf("Plane ID :         %d\n", planes[count].planeid);
        printf("Destination :      %s\n", planes[count].destination); 
        char * time_str;
        time_str = ctime(&planes[count].time);
        printf("Depart Time/Date : %s \n", time_str);
        count++; 
    }

Solution

  • You increment count twice each loop:

    for (int count = 0; count < size; count++) 
     //                               ^^^^^^^ HERE
    {
        ..
        count++;   // HERE
    }
    

    Remove the second count++; on the end of function body.