This is an example from my textbook. I was studying for an exam and after compiling a program I got surprising results. The book didn't mention it at all. Can anybody explain what happened?
The output is:
currentdate is Mon Dec 09 21:25:26 2002
Tomorrow is 12/10/20102.
0.05 seconds used by the processor.
Press any key to continue
Where did the 20102 come from??? What I don't know about time() then?
And the code is:
Code:
#include <time.h>
#include <stdio.h>
int main( void )
{
time_t t1;
struct tm *tptr;
clock_t ticks;
char *s;
if ( ( t1 = time(( time_t * ) 0 )) != ( time_t )-1 ) {
s = ctime( &t1 );
printf( "currentdate is %s", s );
tptr = localtime( &t1 );
printf( "Tomorrow is %d/%d/20%d.\n",
tptr->tm_mon+1,
tptr->tm_mday+1,
tptr->tm_year );
}
else
printf( "Error with the time() function\n" );
if (( ticks = clock() ) != ( clock_t )-1 )
printf( "%4.2f seconds used by the processor.\n",
(double)ticks/CLK_TCK );
else
printf( "Error with the clock() function\n" );
return 0;
}
Thanks