-1

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++; 
    }
  • What are the values for the `.time` members of your array of structures? The `ctime` function can fail if one of those is invalid, or has a year value >= 10000. – Adrian Mole Aug 01 '21 at 14:08
  • @AdrianMole I put it as a random value up to 9999. I just updated the code with the function that initializes the time. – tinkertailor Aug 01 '21 at 14:13
  • 1
    What is `planes`? How is defined? Please post an [MCVE] - some `#include`s, a short `main()`, a full program. – KamilCuk Aug 01 '21 at 14:13

1 Answers1

2

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.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111