I doubt any C programmer has memorized all of the printf() function’s placeholders, options, and settings. It’s a character salad of interesting and weird things. One of the strangest has to be the %n placeholder.
Continue reading
Simplifying Fractions
Difficulty: ★ ★ ★ ☆
Recently, I wrote code to calculate odds. The program’s output listed the odds as a fraction, such as 1/6 for rolling a specific number on a die. But occasionally, the output is something like 7/21. As a human, and after a modicum of mental sweat, I recognize 7/21 as 1/3. The challenge is how to get the computer to recognize and report the smaller fraction.
Continue reading
How Many Characters Output?
I don’t think I’ve ever used the return value from a printf() statement. Yes, the function has an int return value, which is the number of characters output. This value can be difficult to guess.
Continue reading
Variable Scope
In C programming, variables declared within a function are local to the function. Specifically, they’re the auto storage class, the default. External, or global, variables are defined outside of a function declaration and are of the extern storage class. These variables are available to all functions. But the scope within a function can also be limited, depending on where the variable is declared.
Continue reading
Capturing a Program’s Return Value in Linux
As I wrote in last week’s Lesson, the system() function can’t be used in Linux to obtain a program’s return value. Instead, you must use one of the execl() family of functions. Further, this function must be spawned as a child process. This task involves using the fork() and wait() functions.
Continue reading
The Microwave Problem – Solution

The challenge for this month’s Exercise is to write a microwave oven input routine: The user types in a given number of seconds and your program translates the value into the proper number of hours, minutes, and seconds. This type of problem may sound familiar.
Continue reading
Capturing a Program’s Return Value
At the end of the main() function, a return statement must surrender an integer value to the operating system. Does a higher value please the OS? Is it offended by zero? What exactly happens with the value returned when your program is done?
Continue reading
The Microwave Problem
Difficulty: Medium
‘
I have a smart microwave oven. Say I need to heat my tea for a minute and a half. I type in 90. When I press the Start button, the 90 transforms into 1:30, a minute thirty. It’s the same quantity of time, but expressed differently. Such magic is merely clever programming.
Continue reading
Oops: A (Not Really) 3D Array
I screwed up some code in a most delightful manner, all without knowing what I did. In fact, it was a student who ran my less-than-brilliant code and discovered the obvious flaw. But I was clueless.
Continue reading
My Own strcasecmp() Function – Round Three
The strcasecmp() function isn’t part of the standard C library, though many compilers feature it. As having the function is handy, I wrote about crafting your own version back in 2019. Alas, that implementation is flawed.
Continue reading