Mail Archives: djgpp/1996/06/06/15:03:56
:>:>Can anyone tell me why this code doesnt work in djgpp.
:>:> ...
:>:> clock_t start, end;
:>:> start = clock();
:>
:>:> delay(2000);
:>
:>:> end = clock();
:>:> printf("The time was: %f\n", (end - start) / CLK_TCK);
:>:> ...
:>Try this
:>
:> ...
:> clock_t start, end;
:> double timetaken;
:>
:> start = clock();
:> delay(2000);
:> end = clock();
:>
:> timetaken=(end-start)/CLK_TCK;
:> printf("The time was: %f\n", timetaken);
:> ...
:>
:>It works for me. I guess somehow printf truncated the value.
:>Correct me if I am wrong.
Yes, I think you're wrong. The problem is that (end-start)/CLK_TCK is
an integer value, where printf is waiting for a float value. You
can try :
printf("The time was: %f\n", 1.*(end - start) / CLK_TCK);
that should work.
--
Eric Nicolas <nicolas AT dsys DOT ceng DOT cea DOT fr>
Take a look to the SWORD home page :
france: http://bunny.ensea.fr/Pages_Perso/Cedric_Joulain/sword.web/home.html
us: http://www.iquest.net/~cworley/sword.web/home.html
- Raw text -