-
March 10th, 2005, 10:33 PM
#1
Time code and timer
Hi, here is some useful code, the first one is the current date and time, and the second one is a cool little timer.
/*Date and time*/
#include <stdio.h>
#include <time.h>
int main ()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "Current date and time are: %s", asctime (timeinfo) );
getch();
return 0;
}
On this next code you can change the 10 in the for loop to whatever number you want the counter to start.:
/* Timer decrements from 10 to 1!*/
#include <stdio.h>
#include <time.h>
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}
int main ()
{
int n;
printf ("Starting countdown...\n");
for (n=10; n>0; n--)
{
printf ("%d\n",n);
wait (1);
}
printf ("Blast off!!! NASA we have lift off!!!\n");
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|