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
Author Archives: dgookin
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
Fun with switch case, Part I
The switch-case construction, or switch statement, provides your code with a decision tree that both easy to read and to debug. This construction is a bit daunting for the beginner, but becomes more familiar as you use it. It’s not without its quirks.
Continue reading
Creating Your Own Environment Variables
Programs use environment variables, thanks to the getenv() function shown in last week’s Lesson. They can also create their own environment variables, reset variable values, and remove variables.
Continue reading
Peering into the Environment
The operating system’s environment provides temporary storage for variables, settings, and options. These values are easily accessible from any C program. One of the first posts I made on this blog was about accessing the environment. Time to revisit.
Continue reading
Positive Negative Positive Negative – Solution
This month’s Exercise presents what I often refer to as a code “toggle.” Many paths lead to a solution.
Continue reading