c clock

Solutions on MaxInterview for c clock by the best coders in the world

showing results for - "c clock"
Luis
02 Oct 2016
1/** A working clock of time and date
2   that using your own computer's
3   local time to run the clock
4   without setting the time and date
5   in the code itself.               **/
6
7//C libraries statement
8#include <stdio.h>
9#include <stdlib.h>
10#include <time.h>
11
12//Programming the delay command
13void delay(int secondsNumber)
14{
15	int milliSecondsNumber = 1000 * secondsNumber;
16	clock_t startTime = clock();
17	while(clock() < startTime + milliSecondsNumber);
18}
19
20//Driver program
21int main(void)
22{
23	//Declaring the variable
24	char buff[100];
25	
26	//Making the clock run forever
27	for(; ;)
28	{
29		//Seting the clock over your computer local time
30		time_t now = time(0);
31		strftime(buff, 100, " %H:%M.%S \n %d/%m/%Y", localtime(&now));
32		
33		//Cleaning the command line and printing the clock
34		system("cls");
35		printf("\n %s\n", buff);
36		
37		//Seting a delay of one second between each print
38		delay(1);
39	}
40}
41
42///The code itself without the details:
43
44#include <stdio.h>
45#include <stdlib.h>
46#include <time.h>
47
48void delay(int numOfSec)
49{
50	int numOfMilliSec = 1000 * numOfSec;
51	clock_t startTime = clock();
52	while(clock() < startTime + numOfMilliSec);
53}
54
55int main(void)
56{
57	char buff[100];
58	
59	for(; ;)
60	{
61		time_t now = time(0);
62		strftime(buff, 100, " %H:%M.%S \n %d/%m/%Y", localtime(&now));
63		
64		system("cls");
65		printf("\n %s\n", buff);
66		
67		delay(1);
68	}
69}