[Courses] Using <time.h>

Sujita Purushothaman sujita at mimos.my
Thu Oct 10 14:30:51 EST 2002


Abel Pires da Silva wrote:

> I'm trying to put a time function on the program to
> count how much time (in seconds) for the program to
> open a file, read its content until the program
> finished made comparation...

One way to do this would be :
declare two variables of type time_t;
when you want to start counting the time , call the function time(
variable1);
when u finish your work , again call the function time(variable2);
variable2-variable1 should give you the time taken in seconds.
This is ok if you want time that is correct to the second only.
(You might have to cast the variables to integers when performing
subtraction and include time.h)

Rgds,
Sujita





More information about the Courses mailing list