As a string, a phone number is easy to parse, left-to-right, as shown in last week’s Lesson. As a value, however, the processing requires mathematical manipulation to work it from left-to-right.
Continue reading
Author Archives: dgookin
A Nutty Non-Loop
Difficulty: ★ ★ ★ ★
Loops are fun. They’re easy to learn. But not everything that repeats in a C program is constructed as a loop.
Continue reading
The Phone Number String
This Lesson’s topic is more about database programming than C programming, but the philosophy still applies. When do you store a number as a value as opposed to storing it as a string? Two famous examples are zip codes and phone numbers.
Continue reading
To Prefix or Postfix
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
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
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