Despite teaching the C language, I still find myself at odds with pointers. Specifically, it’s the double pointers that remind me of my mortality. I found myself getting into the double pointer polka recently when I tried to work with an array of strings, passing each one individually to a function. O! The pain!
Continue reading
Category Archives: Lesson
Negative Array Elements
I enjoy it when an experienced coder reviews my stuff. I’m happy with the feedback, and occasionally they toss me a bone. This time it was a rather obscure bone, but I see the point: Avoid using negative array elements.
Continue reading
Characters, Values, and Playing with Your Brain
I’ve messed with characters as values quite a few times in my code. Keeping in mind that the char data type is really a tiny integer value, you can perform all kinds of tricks — stuff that drives non-programmers crazy.
Continue reading
Reading strings with the sscanf() Function
I’m not a fan of the scanf() function. It’s an input function, quick enough to toss out there for a beginner to write a (somewhat) interactive programs. But the function itself is horrid, with complex arguments and dubious results.
So imagine my delight at finding its companion function, sscanf().
Continue reading
Discovering Command Line Options, Part V
Somewhere along the line, shell commands developed longer, verbose versions of their original, short command line switches. So in addition to -o you also could use --output. These switches offer readability and are easier to remember. Alas, the getopt() function doesn’t process them, but its sibling function getopt_long() does.
Continue reading
Discovering Command Line Options, Part IV
Some command line switches stand alone. Others are followed by options, such as a starting value, filename, and other settings. The getopt() function processes these values along with the switches, providing you know the secret.
Continue reading
Discovering Command Line Options, Part III
Continuing from last week’s Lesson, to read multiple command line arguments, you must put the getopt() function in a loop. Specifically, you set the function as the looping condition. The loop’s guts evaluate the switches found.
Continue reading
Discovering Command Line Options, Part II
I suppose smart equates to quirky in most programming circumstances. This maxim definitely holds true for the getopt() function. Before you can appreciate this function and put it to use, you must understand how it works and why it can be quirky.
Continue reading
Discovering Command Line Options, Part I
The getopt() function is perhaps one of the most versatile functions I’ve encountered in my C programming journey. It plucks out switches from the list of command line arguments, processing valid ones and spitting out the trash. It’s really quite amazing, but it’s not without its quirks.
Continue reading
More Globbling with the fnmatch() Function
Globbing is the use of wildcards to match filenames, which is something I touched upon a few Lessons ago. It lead me to the glob() function, which reads a pathname for matching files. Often mentioned along with the glob() function, is the fnmatch() function, which serves a similar purpose.
Continue reading