0

I am reading from a file (fp) fourplets, that represent packets and if the generation time of the packet is less than the time running, then I am inserting it in to my list. The time increases by 20.0 every time slot. But I want to check all the packets from the file for the time between 0 and 20 and then between 20 and 40 etc. For example if a packet has generation time 13.9 and the time slot is 0-20, that means the packet will be inserted in the list, but another packet with generation time 24.5 will not be inserted in the list. I wrote the code below but it does not work like that.

  double time=0.0;  
  while( fgets(buf,sizeof(buf),fp) != NULL ){
    fscanf(fp, "%d %d %d %lf",&rollnumber, &src, &dest, &gentime);
    printf("time: %.1f\n",time);
    while (gentime<time && insertedpackets<=10){ 
            insert(rollnumber,src,dest,gentime);
            insertedpackets++;
            display();
        }time=time+20.0;
wajaap
  • 273
  • 3
  • 20
  • Show a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – fpiette Jun 05 '21 at 17:12
  • 1
    I mean, if a packet has generation time=16.5, it will be inserted in the list because the time slot will be 0-20. On the other hand if a packet has generation time=23 it will not be inserted in the list for the same time slot. But I want to check all the packets from the file until the last one for the same time slot. – wajaap Jun 07 '21 at 15:49
  • You still have to provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) that we can play with. Of course we need also some sample data to test with. – fpiette Jun 07 '21 at 17:25
  • 1
    From your description, it seems like you would just want to compute `floor(gentime/20.0)` to figure out which time slot a given entry belongs to and then just insert it into that slot's list? – Chris Dodd Jan 25 '22 at 22:22
  • @Chris Dodd could you explain this more? It’s a bit confusing – wajaap Jan 25 '22 at 22:59

0 Answers0