post  something abt time()

CD4 (28)   Link to this post
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include  <time.h>
#include  <stdio.h>
#include  <unistd.h>
#include  <stdlib.h>
int main()
{
    int i;
    time_t the_time;
    for(i = 1; i <= 10; i++) {
         the_time = time((time_t *)0);
         printf(“The time is %ld\n”, the_time);
         sleep(2);
    }
    exit(0);
}

in this example i dint get line 9 time((time_t *)0);
can please some1 help.Code is from the book Beginning linux programming 4th ed.

regards
Bazzy (4107)   Link to this post
From http://www.cplusplus.com/reference/clibrary/ctime/time/ :
The function returns this value, and if the argument is not a null pointer, the value is also set to the object pointed by timer.


(time_t *)0 casts 0 ( NULL ) to a pointer to time_t
CD4 (28)   Link to this post
so bazzy... cant time(NULL) be used aas in example?? what is the significance of the lines coded above (type casting)??

regards
Bazzy (4107)   Link to this post
There isn't any difference so you can put that.
CD4 (28)   Link to this post
thanks bazzy... :)

This topic is archived - New replies not allowed.