Thread: problem with my time code

1. problem with my time code

It prints same values for in all the loop.
and it doesn't add properly new_time.time and new_time.millitm
meaning,
when I print them separately , their value added together doesnt match up with last_time.
Code:
```void time()
{
struct timeb new_time;
double  last_time,latest_time, interval_time = 0, real_interval_time;

ftime(&new_time); //init purpose
last_time =(double)new_time.time+(double)(new_time.millitm * 0.001 );
printf("last_time=%lf\n",last_time);

while(1)
{
ftime(&new_time);
latest_time=(double)new_time.time+(double)(new_time.millitm * 0.001);
printf("latest_time=%lf\t",latest_time);

real_interval_time = latest_time - last_time;
printf("rit=%lf\t",real_interval_time);
interval_time += real_interval_time;
printf("it=%lf\n",interval_time);
last_time = latest_time;
}

}```

2. It works fine for me. In one loop not enough time passes, so in order for the "it" to change you need like 30 iterations or sth. "rit" is almost always 0 or like 0.01.

In any case this is surely better:
Code:
```last_time =(double)(1000*new_time.time)+(double)(new_time.millitm * 0.001 );
...
latest_time=(double)(1000*new_time.time)+(double)(new_time.millitm);
printf("it=&#37;lf\n",interval_time / 1000);```
since you don't lose accuracy by dividing multiplying by 0.001!

So it is always the same for you?

EDIT: Also note that time() already exists in so you might want a different name <sys/time.h>