www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/06/15:03:56

Xref: news2.mv.net comp.os.msdos.djgpp:4675
From: nicolas AT dsys DOT ceng DOT cea DOT fr (Eric NICOLAS)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Why doesnt this work!
Date: 5 Jun 1996 12:52:49 GMT
Organization: Commissariat a l'energie atomique, Grenoble (France)
Lines: 43
Message-ID: <4p3vv1$ocg@news.cea.fr>
References: <4p3uct$h50 AT raffles DOT technet DOT sg>
Reply-To: nicolas AT dsys DOT ceng DOT cea DOT fr
NNTP-Posting-Host: hudson.ceng.cea.fr
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

:>:>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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019