For whatever reason, it’s your desire to split a real number into its integer and fractional parts. Perhaps you’re angry with the value. Regardless, I can think of a few ways to perform this feat, but need not exercise a single brain cell in this effort as the modf() function performs the task automagically.
Continue reading
Author Archives: dgookin
Testing Your Pointer Prowess – Solution
The solution for this month’s Exercise is to output the string "I am an excellent C programmer"
. This task isn’t so simple when you must untie the knot of the dratted double pointer.
Continue reading
How Whacky is that Real Number?
If you’ve tried your computer’s patience, you may have encountered some valid yet odd results when doing math. For example, you may see NaN
output, which is computer-speak for “Not a number.” Or perhaps you’ve encountered INF
, infinity. The C library offers a way to test for these results before they’re output.
Continue reading
Testing Your Pointer Prowess
Difficulty: ★ ★ ★ ☆
Pointers can drive C programmers mad. In fact, I’d say that evidence of this notion is that the most experienced C programmers have an air of insanity about them. To join their club, try working this month’s Exercise.
Continue reading
Finding Structures with the bsearch() Function
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
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
Emulating the Modulus Operator – Solution
In an alternative universe, the C programming language lacks a modulus operator and no companion function exists in the library. What to do! Why, you code your own modulus function, which is the challenge for this month’s Exercise.
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