It’s easy to explain the bsearch() function when using integers. One step up is to search for strings, covered in last week’s Lesson. At the pinnacle of insanity, however, is searching through an array of structures.
Continue reading
Category Archives: Lesson
Using the bsearch() Function to Find Strings
When learning the bsearch() function, it helps to start with integers, as demonstrated in last week’s Lesson. When the data is more complex, however, additional programming kung-fu is required to sort and search. The first hill to climb in this adventure is to hunt down a string.
Continue reading
The bsearch() Function
Computer scientists, as well as various professionals wearing white lab coats, have determined that searching for data top-to-bottom is slow and clunky. Therefore, they devised a better, more logical way to search: The binary search.
Continue reading
O Value! Where are You?
Finding things is an unwanted pastime for humans. “Where are the good scissors?” “Who has seen the cat?” “What happened to all my money?” These issues don’t exist for a program that dutifully locates any data tidbit without complaint. Finding the smallest needle in the largest haystack isn’t an issue for a computer.
Continue reading
Building a String
Programming language more modern than C sport great libraries of functions, or “methods.” Java has so many I doubt that a single programmer knows them all. In C, however, when a function is absent (and a lot of them are, comparably), you must code your own. Such is the case with building a string.
Continue reading
The Pig Latin Translator, Part III
The final step in my Pig Latin journey is to process an entire English language sentence. The piglatin() function, finished in last week’s Lesson, requires no updates. But chopping a sentence into words and sending them off to be processed individually proved to be an interesting exercise.
Continue reading
The Pig Latin Translator, Part II
From last week’s Lesson, the piglatin() function swallows a word and returns its Pig Latin translation, but only for words starting with a vowel. The operation for words that begin with a consonant is more complex.
Continue reading
The Pig Latin Translator, Part I
One of my older C programming books featured a sample program that translated English words into their Pig Latin equivalent. It’s time to revisit this code.
Continue reading
What is That Defined Constant’s Value?
The C language uses defined constants to represent consistent values across platforms. For example, the PATH_MAX value might be 260 on one system and 4096 on another. It’s not important to know the specific value, just use the defined constant and your code builds and runs on various systems (hopefully).
Continue reading
Sorting the Hexwords, Part II
The problem with the code from last week’s Lesson is obvious: The decimal value of FEED is 1,044,205, not 2,314,885,530,818,453,605 as shown in the output. Before I can sort the list numerically, this error must be addressed.
Continue reading