Declaring an array of strings as a pointer has many advantages, as demonstrated in last week’s Lesson. Above all, I like that I don’t have to calculate the longest string’s length to set the size for the second dimension. But what happens when set this size incorrectly?
Continue reading
Keep Finding That String – Solution
The task for this month’s Exercise is to repeatedly call the strstr() function, locating all instances of one string (“needle”) inside another (“haystack”). Obviously your first task, which also helps with the solution, is to perform error checking on the return value from the strstr() function.
Continue reading
Rotating an Array of Strings
Last month, I posted about rotating values in an array. This post used integers, but the question has come to me about doing the same thing with an array of strings. Yes, it’s possible — and just as easy.
Continue reading
Keep Finding That String
Difficulty: ★ ★ ☆ ☆
One of the most clever string functions is strstr(), which searches for one string within another. Because of its return value — a char pointer — it’s possible to call this function multiple times to continue searching through the string.
Continue reading
Flipping the Data
Just as it’s possible to rotate elements in an array, shuffling them all up a notch and moving the first element to the end, it’s also possible to flip an array, reversing the order of its elements.
Continue reading
Rotating the Data
You wait all day in line — you know, one of those bureaucratic government things — only to get to the front of the line and discover that you’re missing something. So back to the end of the line you go, ready to toil all over again. Sound familiar? But a computer wouldn’t care.
Continue reading
Splitting a Decimal Value
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
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