The challenge for this month’s Exercise is to count in “alphabedecimal,” generating output from AAAA through ZZZZ, without using nested loops or a complex if structure. Your solution must use a recursive function that handles flipping the digits, er, characters.
Continue reading
Author Archives: dgookin
Frying a String
The challenge for September’s Exercise is to scramble a string, jumbling its characters in a random pattern. I figured it’s a fun exercise, not anything useless beyond curiosity. Yet such a function exists for the GNU C library, strfry().
Continue reading
Alphabedecimal Revisited
Difficulty: Medium
The goal of the November 2018 Exercise on this blog was to count in “alphabedecimal,” or base 26 using the uppercase letters of the alphabet. The solution cycles from AAAA to ZZZZ flipping each character (or digit) one at a time, just as numbers are counted. The challenge is to do so without employing a nested loop.
Continue reading
The strerror() Function
System errors happen. Your program accesses the operating system and . . . something goes wrong. When it does, the function returns -1 and your code must rely upon our old buddy errno to discover what went wrong and possibly output an informative error message.
Continue reading
Magic Numbers
There’s a scene in the HBO series Silicon Valley that aptly describes a magic number in programming code: Coders are trying to figure out a compression algorithm and they encounter a large integer value. They wonder what it means; it’s not commented or assigned to a clever constant name. It’s just . . . a magic number.
Continue reading
Is it Bad to Cast malloc()?
In my code, in my books, and in my online courses, I typecast the malloc() function. This is something I’ve done for a while, but never really knew why — until now. I’ve also learned that doing so is considered “bad programming practice” by some in the C community.
Continue reading
Scramble a String – Solution
For this month’s Exercise, my solution to the scramble() function requires a second array. You could code a scramble() function without using a second array (or storage buffer), swapping individual characters within the string, but I chose not to.
Continue reading
When Passing a String to a Function, Be Careful That You Don’t . . .
Passing a string to a function? Check!
Passing an array of strings to a function? Watch out!
Continue reading
Scramble a String
Difficulty: Hard
Most functions are nice to strings. They manipulate the characters in a useful or clever way, returning an important value or an updated version of the text. But not every string function needs to be so kind, such as the one you write for this Exercise.
Continue reading
Manipulating a String in a Function
You have two choices when modifying a string in a function: You can modify the string directly or you can create a new string and return it. Either way, a new string is created based on the old.
Continue reading