This month’s Exercise may not have been challenging. Still, remember that blog is about learning the C language. Sometimes performing what could be a simple task may end up being complex than you anticipated.
Continue reading
Author Archives: dgookin
Reading the Keyboard Queue ala Networking
A network program monitors one or more file descriptors (such as sockets) for activity. It reacts when information is ready to process. This technique can also be applied to keyboard input, though not as elegantly as the kbhit() function shown in last week’s Lesson.
Continue reading
Calculating the Absolute Value
Difficulty: ★ ☆ ☆ ☆

I started my technology writing career at a computer book publishing house, CompuSoft. It’s no longer around, but I do recall ghost writing books such as the BASIC Handbook, which was an encyclopedia of the BASIC programming language. The first command listed in this book was ABS.
Continue reading
Looking for a Keyboard Hit
The C language is famously platform independent. This feature may seem unimportant these days, but back in the early computer era having a language you code code on multiple systems was key to the C language’s success. This benefit may be one reason why C lacks a specific function to check on the keyboard status to determine whether a key has been pressed. Such a function is hardware-dependent.
Continue reading
What’s Next, Keyboard?
Suppose you must write code that remains busy while checking to see whether a key has been pressed. The program repeats a loop, performing various tasks, but eager for that key press. When a key is pressed, the code fetches the key. Two things stand in your way to make this happen.
Continue reading
Squaring a Value
The C language lacks an operator that squares a value or, more generally, raises a value to a specific power. To do so, use the pow() function. Yet I’m finding the need for a square() function as I explore some interesting and obscure mathematical thingies.
Continue reading
The alloca() Function
Any memory allocated in a function is retained when the function leaves, unless you first free it. This rule applies to all memory allocation functions — except one.
Continue reading
Calculating the Subfactorial – Solution
Do you feel adequately deranged working this month’s Exercise? I’m more of a math fanboy than an expert, yet I enjoyed the process of coding a subfactorial based in the equation presented.
Continue reading
Fun with switch case, Part II
In last week’s Lesson, I reviewed the switch-case structure and how declared constants aren’t truly the kind of constant a case statement requires. This week I continue my exploration of switch-case, with an interesting and surprising quirk of the default condition.
Continue reading
Calculating the Subfactorial
Difficulty: ★ ★ ★ ★
Calculating a factorial is a common programming exercise, often coupled with introducing the concept of recursion. Mathematically, the factorial has a twin: the subfactorial. Its calculation can be a fun programming challenge, which is the subject of this month’s Exercise.
Continue reading