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
Author Archives: dgookin
π 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
Suppressing a Terminal’s Character Echo
Back in the bad old days, you used a terminal connected to a mainframe to do your computer work. The terminal had a monitor and keyboard and just enough smarts to configure itself for communications with the mainframe. One of those configuration options was character echo.
Continue reading
Input Minus the Echo
The prompt appears in the terminal window: Type your password
. As you type the password, text doesn’t appear on the screen. Yes, the program is using stream I/O. So how do you code standard input that doesn’t output characters?
Continue reading
Yet Another Oddball: Token Paste
I’m constantly on the prowl for obscure and seldom-used C language functions and techniques. One I just discovered — despite coding in C for decades — is the token paste operator. It’s a weirdo.
Continue reading
Hunt the Wumpus Code
I had a great time coding Hunt the Wumpus. Like most programming challenges, it was fun, exciting, and frustrating all at once. Some code ran beautifully the first time. Other code contained silly mistakes that bogged me down. And solutions unveiled themselves magically like a sugar cube dissolving in water.
Continue reading