home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
c
/
cuj9301.zip
/
1101116B
< prev
next >
Wrap
Text File
|
1992-11-03
|
891b
|
42 lines
/* time2.c: Compute a future date */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
main()
{
time_t start, stop;
struct tm *now;
int ndays;
/* Get current date and time */
time(&start);
now = localtime(&start);
/* Enter an interval in days */
fputs("How many days from now? ",stderr);
if (scanf("%d",&ndays) != 1)
return EXIT_FAILURE;
now->tm_mday += ndays;
if (mktime(now) != -1)
printf("New date: %s",asctime(now));
else
puts("Sorry. Can't encode your date.");
/* Calculate elapsed time */
time(&stop);
printf("Elapsed program time in seconds: %f\n",
difftime(stop,start));
return EXIT_SUCCESS;
}
/* Output
How many days from now? 45
New date: Fri Nov 20 12:40:32 1992
Elapsed program time in seconds: 1.000000
*/
/* End of File */