Description
Objectives
Making you familiar with,
- Arrays
- Loops
- Functions
- Command-line argument handling
- Debugging
- Good coding practices
- Linux environment
Introduction
You have to develop a digital clock that prints the current time, and date on the linux terminal. If a color is given as an argument to the program, the program should be able to print a colored output. You will be given a sample program (prog) that would do the same task. Your task is to replicate the functionality of the given program. Below figures show the expected output from your program.
The output should print exactly at the same place and scale as the given program
(prog)
Inputs:
Command-line arguments:
- If a colour is given as an argument to the program with the ‘-c’ flag, the program should be able to print the clock using the given colour. If no argument is given, use black and white as default.
Eg: ./prog -c red
- These colors should be supported by the program – black, red, green, yellow, blue, magenta, cyan
- If -h flag is given or the given arguments are invalid, you should print the usages of your program (how the arguments should be given). See the sample binary given for the expected behaviour.
Problem breakdown
Instead of directly going to code the solution, you must break down the problem into smaller subproblems, such as
- How to get user inputs as arguments
- How to get the current system time
- How to get the current system time as a string
- How to print a number
- How to print multiple numbers at different positions
- How to print the date
- How to assign a color to printed characters
- Error handling for the program
Instead of thinking about the problem as a whole, try and find the solutions for each one of the above questions. That will help you to reach the final goal smoothly and accumulatively.



