The challenge for this month’s Exercise is to determine whether an integer, 1 to 100, is divisible by nine or contains the digit ‘9’. It seems like an easy puzzle for a C programmer to solve, but what I found interesting was crafting the output — specifically when a number both contains ‘9’ and is divisible by nine.
Continue reading
Author Archives: dgookin
Writing File Data in the Raw
Along with open() as a raw file access function comes raw functions to read and write data. Last week’s Lesson covered the read() function. This week covers its twin sibling, write().
Continue reading
No Nines!
Like many innocent and silly math games, No Nines is nerdy to play but fun to code. The game works like this:
Continue reading
Raw Reading File Data
When you use the fopen() function to open a file for reading, a buncha functions are available for reading data: fread(), fgets(), fgetc(), and others I’m too lazy to look up. Reading files by using the open() function, however, gives you this choice: the read() function.
Continue reading
Opening a File in the Raw
The fopen() function opens a file or stream for formatted input. The “formatted” is where the function gets its f prefix, which I always thought stood for file. It doesn’t. The fopen() function is the formatted file (and stream) function, the open() function is for low-level, unformatted file access.
Continue reading
π Day Bonus!
I plan my Lessons weeks in advance. So, only recently did it dawn upon me that today is March 14th, 3/14, known to nerds all over as Pi Day. Here is yet another nerdy program I wrote to calculate the value of π:
Continue reading
Three-Way Evaluations
Being traditional and, to be honest, ancient, the C language deals primarily with two-way evaluations: a > b, c != d, r <= 0, and so on. Complex comparisons build upon these atomic nuggets, but among the trendy languages a newer alternative exists: the three-way evaluation.
Continue reading
Dump That File! – Solution
I’ve been coding hexdump utilities since the microcomputer era. They’re just so handy, especially when writing structures or other formatted data to a file. The dump assists with debugging, and it helps you figure out some undocumented data structures as well.
Continue reading
Outputting Inverse Text
Early computer terminals were text-only output devices. Sure, some got fancy and could do color text, perhaps even underline. Many of the early terminals, as well as the first handful of microcomputers (ancestors of the modern desktop), generated only text with perhaps some inverse text to spice things up.
Continue reading
Dump That File!
One of the many, useful tools a programmer must have is a hexdump utility. The utility consumes a file’s raw bytes and outputs them in a human-readable manner. By examining the dump, you can determine if file contains the proper data in the correct format, as well as do other interesting, useful, and technerd things.
Continue reading