I am not a math genius, as any math genius who reviews my work is happy to tell me. Even so, when programming I’m often faced with math challenges where a math education would benefit. My most recent puzzle is how to count the number of digits in a value without first converting the value into a string.
Continue reading
Author Archives: dgookin
Converting Month Strings to Integers
I saw this problem on stackoverflow: How can you take a month string and convert it into an integer value, one through 12? The student submitting the query used a long if-else if-else construction. I have a better idea.
Continue reading
From ‘A’ and ‘a’ to ‘Z’ and ‘z’ – Solution
I don’t believe one definitive solution exists for this month’s Exercise: Output a string of upper- and lowercase letters. No, the challenge is more to discover different insights a coder has to a specific problem.
Continue reading
Going Mad for Mod
I have two questions when it comes to using the % operator: Is it modulus or modulo? And which value comes first?
Continue reading
From ‘A’ and ‘a’ to ‘Z’ and ‘z’
Difficulty: ★ ☆ ☆ ☆
Here’s an easy exercise to try, something for those first learning C programming but also a challenge for experienced users: Output the alphabet A to Z in both upper and lowercase letters. It’s an “easy” exercise only when you don’t explore the possibilities.
Continue reading
Forcing a Decision
Programs often ask questions: yes-or-no and multiple choice. The user must select one of the given options, which I refer to as forcing a decision. Your goal as programmer is to pester the user to input a valid choice.
Continue reading
Returning a Non-Static String
It’s possible to return a string created in a function without declaring it static. This trick requires some understanding of how functions return values. Nerd alert!
Continue reading
Having Fun with the getline() Function
In last week’s post, I updated information I had originally written about the useful getline() function. The topic is worthy of further exploration, specifically with the mechanics behind the function’s internal allocation — and reallocation — of memory.
Continue reading
The getline() Function – Update
Back in early 2015, I wrote about the getline() function, which is a handy way to read a string. I’ve been informed that my post is the top result for a Google search on getline() — and I have an update!
Continue reading
Your Own Version of left-pad() – Solution
Can you write your own left-pad function in C? Would you get so angry that you’d pull it from the Jenga-tower NPM and bring the Internet to its knees? I hope your answer Yes to the first question and No to the second, because your task for this month’s Exercise is to write that function.
Continue reading