Suppose that you’re testing code and need to run a program six times in a row. You could keep repeating the program, running it multiple times, but why not write a utility that does the same thing? That would be a good and practical way to put the system() function to work.
Continue reading
Category Archives: Lesson
Hello, System
One thing that continues to puzzle me about learning the C language is how frequently beginners use the system() function. Is it a crutch? Is it a necessity? What’s the allure of this function that makes it show up in beginner code?
Continue reading
Before You Say Goodbye . . .
The standard C library contains a lot of interesting and unusual routines. Some can really put the fun into function. One of them I’ve rarely used, but which can be extremely handy, is atexit().
Continue reading
Build Your Own strcasestr() Function
I was a bit surprised the other day. I’d written code on my Macintosh and tried to run it on the PC. Because I usually write generic stuff, I figured that the code would compile and run on both systems. But it didn’t compile.
Continue reading
Parsing the Command Line IV
Command line options often sport their own options or settings. For example, tab width might be set by specifying the tabwidth option followed by a value. No hard and fast rules exist for how such an option is set, but I’ve seen it happen in one of three ways:
Continue reading
Parsing the Command Line III
Your code must consider whether or not command line options are present, that the user may type the options in any order, and that some or all of the option could be incorrect. That makes for a lot of processing, but it’s also forgiving and users prefer the flexibility.
Continue reading
Parsing the Command Line II
When processing the main() function’s arguments, you must keep in mind the possibilities. Options are, after all, options. They might be there, they might not.
Continue reading
Parsing the Command Line I
About a year ago, I wrote a post on reading the command line arguments. It’s a process that takes place all the time, not only when running programs in a terminal window but also for graphical operating systems. Knowing how to manipulate command line arguments is important.
Continue reading
Quicksorting Strings, Pointer Edition
I’ll confess that when I use a quicksort to sort and array of strings, I don’t use the C Library’s qsort() function. No, I write my own. The problem is that when sorting an array of strings, the qsort() function’s compar argument is a pain in the butt to craft properly.
Continue reading
Quicksorting Strings
The quicksort deftly handles vast quantities of values. It can also sort strings, but that’s where things can get weird.
Continue reading