DigitalClock in C A simple Digital Clock program written in C that displays the current time and date in various formats. The program continuously updates the time and date every second and clears the screen to provide a dynamic display.
Features:
- Displays time in various formats: 12-hour format 24-hour format (default) Expanded format
- Displays the current date in the format: Day, Month, Year.
- Cross-platform support: Windows: Clears the console using cls. Linux/MacOS: Clears the console using clear.
Libarary Used:
- #include<stdio.h>
- #include<stdlib.h>
- #include<time.h>
- #include<unistd.h>
Refrences: https://en.cppreference.com/w/cpp/chrono/c/strftime
How to run:
- Complie the program:
-
gcc digitalClock.c -o digitalClock - Run the program:
-
./digitalClock - Choose the format you want to use.
Requirements:
- C compiler
- Operating system
Code Explanation:
- fillTime(char *buffer, int choice): Fills the buffer with the current time in the selected format.
- fillDate(char *buffer): Fills the buffer with the current date in Day, Month, Year format.
- choice(): Prompts the user to select a time format.
- clearScreen(): Clears the console screen for dynamic display.
- main(): Continuously displays the current time and date based on user choice.
Demo:
--------------------Digital Clock------------------------- Choose the time format you want to see: 1. 12-hour format 2. 24-hour format (default) 3. Expanded format Enter your choice: 1 ---------------------------------------------------------- Current Time: 02:30:45 PM Today is: 27, December, 2024 The screen updates every second with the latest time.
License: This project is licensed under the MIT License. You are free to use, modify, and distribute the code.