Being curious, I asked ChatGPT which C programming questions it gets asked most frequently. Some of the topics are complex, such as back peddling through a linked list. I cover double-linked lists on this blog, though I don’t demonstrate how to work backwards through one.
Continue reading
Category Archives: Lesson
A Problem with Strings in Two-Dimensional Arrays
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
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
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
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
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