One of C library functions I find most odd is dup(). I pronounce this function as if it rhymes with cup. I assume others may pronounce it like doop, which rhymes with poop. Whatever. The key is what the function does and how it could even remotely be necessary.
Continue reading
Author Archives: dgookin
Ramanujan Nested Radicals – Solution
The topic for this month’s Exercise is to code a recursive function that solves the Ramanujan Nested Radical, illustrated in Figure 1. Remember that Ramanujan created and solved this puzzle in his head. #genius
Continue reading
Rubbing a File Raw
About six years ago, I wrote about opening a file in the raw. Specifically, using the open() function to access file data at a low level. This approach uses file descriptors (integers) to track file I/O as opposed to the file handles used by the high-level fopen() family of functions. It turns out that you can do more with raw file access than just read and write data.
Continue reading
Ramanujan Nested Radicals
Difficulty: ★ ★ ★ ★
Srinivasa Ramanujan was a mathematician of the genius variety in that he did amazing things in his short lifetime. The man was insanely brilliant. In fact, he struggled to get other mathematicians to understand his work because it was so unfamiliar. Anyway, he concocted the thing shown in Figure 1, which is one of many Ramanujan Nested Radicals:
Continue reading
How Much Stuff Can You Cram In There?
The for keyword opens the door to looping in C, as well as in other programming languages. When teaching this concept, I keep the for loop format simple. After all there’s a lot of cryptic stuff between those parenthesis. And — brace yourself — there’s room for a lot of other stuff as well.
Continue reading
Creating Your Own Library
Anyone who’s programmed in C for a while has worked with other libraries. In Linux, it’s common to link in the math library, libm.a. Other libraries are available to expand what the C language can do. I have books available on Ncurses, curl, XML and JSON, each of which has a library that makes it easy to use these powerful utilities. But what about making your own library?
Continue reading
What the Heck is This?
As I plow the digital seas, I often come across a piece of programming flotsam worthy of investigation. Most of it is obfuscated C, which is delightful. The obfuscated code that outputs something wonderful is most entertaining. But every so often I stumble upon something perplexing like the following code:
Continue reading
Recursion Until Death!
When I first learned Assembly Language, I had a fear of blowing up the stack. Remember, back in the 8-bit microcomputer era that memory space was tight, maybe only part of 64K. A stack would have 1K of storage, if that. I think the stack size on my TRS-80 was 256 bytes. (An address was only two bytes wide.) This limitation meant that pushing too much data on the stack would blow up the computer.
Continue reading
It’s All Greek! – Solution
As a wrap-up for my ctype questions, this month’s Exercise is to write a ctype function that converts lowercase Greek letters to uppercase and vice-versa. This challenge isn’t a steep hill to climb, once you know the pattern of Unicode Greek letter values, and ignore the required accent and breathing marks that frequently adorn various letters.
Continue reading
Happy 250th, USA!

Today is Independence Day in the USA. Two hundred and fifty years ago, this nation’s founding fathers signed the Declaration of Independence. While I’ve had posts dated July 4 previously on this blog, today is a special anniversary. It necessitates a specific C language program.
Continue reading