Being the ancient and venerable programming language it is, C lacks the associative array data type. This type of array is found in other languages, and it can be awkwardly simulated in C.
Continue reading
Author Archives: dgookin
Swapping Variables – Solution
This month’s Exercise challenges you to swap two variables’ values without using a third variable. It’s a solution widely available on the Internet, but your job is to figure out the technique without looking elsewhere.
Continue reading
Pairs of Arrays
I enjoy studying foreign languages. A tool like Google Translate comes in handy, but it’s not perfect. That’s because computers translate words and phrases, but not the living, spoken language. Regardless, I thought I’d give language translation a stab, which got me into the topic of exploring arrays.
Continue reading
Swapping Variables
Difficulty: ★ ★ ★ ☆
The classic paradigm for swapping values between two variables involves using a third variable. But is the third variable even necessary?
Continue reading
The Improved nano_delay() Function (I Hope)
Last week’s Lesson explored using the clock_gettime() function to pause program execution for a given number of nanoseconds. The code, however, contains a flaw that may render an inaccurate result.
Continue reading
Your Own Time Delay Function
I’ve written about my own delay() function, which uses processor clock ticks to calculate a time delay in milliseconds. Thanks to the clock_gettime() function, I can write a new time-delay function that operates from nanoseconds — or close to it. I hope.
Continue reading
Programming with Nanoseconds
From last week’s Lesson, the clock_gettime() function returns values in both time_t (Unix Epoch) seconds as well as nanoseconds. This rich variety makes the function quite useful for coding time-critical details where values less than a second are desired.
Continue reading
Yesterday – Solution
The challenge for this month’s Exercise is to output yesterday’s date: the day of the week, day of the month, month, and year. It’s not as complex as it could be, though keep in mind that any code that outputs the proper result is valid.
Continue reading
Checking the Time
I tend to keep the lessons on this blog specific to the standard C library, C99 release. Yet every so often a newer function draws my attention, which may not be standard but can still be useful. Case in point is the clock_gettime() function, which subscriber M.Stumpfl mentioned in a previous post.
Continue reading
Yesterday
Difficulty: ★ ★ ☆ ☆
The time.h
header defines a handful of functions useful for discovering and manipulating today’s date. Especially the localtime() function, which translates a time_t (Unix Epoch) value into date fields for output or manipulation. It’s a wonderful tool, but what does it tell you about yesterday?
Continue reading