Categories

Subscribe via Email

Enter your email address to subscribe and receive notifications of new content by email.

Difftime example

This shows the difftime function and in this case we will pause our program for 5 seconds with it

#include <stdio.h>
#include <time.h>

int main()

{
time_t start;
time_t current;
time(&start);
printf(“delay for 5 seconds.\n”);
do{
time(&current);
}while(difftime(current,start) < 5.0);

printf(“Finished delay.\n”);

return 0;
}

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBibSonomyDeliciousDiggDiigoSina WeiboWordPressBlogger PostShare

Using the Ctime function

Using the Ctime function

This example shows a sample usage for the Ctime function to display the date and time.

/*using the ctime function*/

#include <stdio.h>
#include <time.h>

int main()
{
time_t tm;
tm = time(NULL);
printf(ctime(&tm));
return 0;
}

This was tested on Visual C++ 6 and LCC Win 32

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInWhatsAppBibSonomyDeliciousDiggDiigoSina WeiboWordPressBlogger PostShare