Recursion is a type of programming loop, one that’s deliberately designed to drive some programmers nuts. It’s also a great way to replace nested loops, such as those used in last week’s Lesson.
Continue reading
Category Archives: Lesson
Brute Force Permutations
If Arthur C. Clarke’s story The Nine Billion Names of God were true, then it seems rather pointless to plow through all 9,000,000,000 permutations to find one matching name. In fact, the exercise is more like a brute-force password cracking program than some celestial name search. What if the monks already knew the name? That would save time and effort.
Continue reading
Permutations
In his 1953 short story, The Nine Billion Names of God, Arthur C. Clarke writes of Tibetan llamas who seek to know all the names of God. They’ve been writing down the names for centuries, but upon the advent of the computer, they enlist western science to help them finish the task in days. You can complete the same task with your computer and the C programming language, but in hours instead of days.
Continue reading
Slicing Strings with strsep()
The strtok() function is the traditional C library routine used to slice up a string. It has its limitations, however, so a more recent function was included in the library on some compilers to replace it: strsep().
Continue reading
String Parsing with strtok()
A handy tool for slicing up a string of text into chunks is the strtok() function. If you understand the strtok() function, it helps you better understand how more complex parsing functions work.
Continue reading
Display Errors and errno Messages Automagically
Last week’s Lesson discussed the errno variable and how it can display more detailed error messages. I have two updates to that Lesson.
Continue reading
The errno Variable
One of the C language’s universal variables is errno. It contains a code describing details about why a particular operation failed. You can use errno in your code to provide better, more informative error messages for your programs.
Continue reading
Your Code Goes “Oops!”
Error messages have a notorious reputation in the computer kingdom. It’s well-deserved, but as a programmer you can better see how error messages evolved. Like documentation, i.e., the wretched manual (which is gone now), error messages are typically an afterthought in the software development cycle. It doesn’t have to be that way.
Continue reading
Give Me a break
I received an email question recently about the power of the break keyword. The answer to the question is that you can only break out of the current loop or switch-case structure. Even in a nested loop, or a switch-case structure within a loop, break affects only the current element.
Continue reading
The ungetc() Function
The standard C library contains a clutch of functions you use all the time, such as printf(), getchar(), malloc(), time(), rand(), and others. If you look in the library, you may discover some oddball functions that you’ve never used. One of those oddball functions might be ungetc().
Continue reading