January 1, 2010

Happy New Year! And best wishes for a healthy and prosperous year for all my readers and their families.

On the first day of a new year it seems appropriate to write an exercise based on calendars. Unix provides a cal command to print calendars. There are several forms:

  • cal — prints a calendar for the current month
  • cal year — prints a twelve-month calendar for the specified year; note that year 10 occurred during the time of Christ, so you must specify 2010 for the current year
  • cal month year — prints a calendar for the specified month and year; the month is given as a number from 1 to 12
  • cal -3 — prints a three-month calendar for the prior month, current month and next month

The current date is highlighted wherever it appears.

Your task is to implement cal. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.


Pages: 1 2