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
Category Archives: Lesson
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
Reading Wildcards from the Command Line
Back in May, I wondered how command line input could be processed when a wildcard is present (Lesson link). My research lead me to the glob() function, but you don’t use this function to process a command line wildcard argument. The reason is that these wildcards are handled by the shell; your code has no direct way to determine when a wildcard is present as a command line argument.
Continue reading
Understanding the Glob
From the history of the Unix operating system, glob is the term used for wildcard matching in filenames. It’s short for global, which to me means that two extra bytes of storage (for 'a' and 'l') were important back in the day.
Continue reading
Wild About Wildcards
Wildcards were highly useful during the glory days of text mode operating systems. They still exist: ? represents a single character in a filename and * represents a group of characters. Using wildcards to manipulate files is a staple of computer file management, perhaps a lost art in the era of graphical operating systems, but still relevant. The C language is also still relevant, so how does it deal with wildcards in a filename?
Continue reading
Creating a Pointer Array (Correct)
Unlike the iffy issue with assigning a pointer directly to a string, you cannot declare a pointer and assign it an immediate value. This puzzle was presented in last week’s Lesson. No, to do things properly requires not a single statement but three separate steps.
Continue reading
Creating a Pointer Array (Wrong)
I’m delighted to receive reader email regarding the various puzzles in the C programming language. Some of them involve creative thinking and approaches that seem like they work — but don’t. Pointers are one of the most common subjects.
Continue reading