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
Author Archives: dgookin
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
Check Your Stock Gains – Solution
The challenge for this month’s Exercise is to determine the greatest price gain for a stock during the trading day. The gain is calculated moving forward in time, from a low to a high. It’s easy to see with human eyeballs looking at a chart, but not so easy when you must code a solution.
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
Check Your Stock Gains
Difficulty: Hard
The challenge for last month’s Exercise was to generate a table showing a stock price updated every 30 minutes during the trading day. This month’s Exercise expands upon the process by having your code examine the stock price highs and lows and determine the greatest increase in stock value. This calculation means more than just finding the high and low values.
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
Watch the Stock Market – Solution
Looks like your stock had a great day at the market. It bounced around, highs and lows, lots of nerves wracked and fingernails chewed, but the price ended higher on the day.
Continue reading