Here’s a thought experiment for you: How can you prompt a user to properly input a percentage value?
Continue reading
The Joy of Bit Fields
One of the C language’s strengths is that it can venture down into the depths of a computer’s inner workings. It loves to play in those dark, subterranean pools of raw data, bits, ports, and other primitive places that few high-level languages dare to tread.
Continue reading
A Recursive Permutation Function
Of course recursion is scary! At no other time in your programming career is your code more susceptible to stack overflows, which appear on the screen as ugly system errors when the code runs. I find that exciting.
Continue reading
Recursive Permutations
Recursion is a type of programming loop, one that’s deliberately designed to drive some programmers nuts. It’s also a great way to replace nested loops, such as those used in last week’s Lesson.
Continue reading
Appreciation for Depreciation – Solution
This month’s Exercise is one of those old, programming warhorses: Calculate a depreciation schedule. At the simplest level, the solution is a mathematical loop and keeps subtracting a given percentage from a value.
Continue reading
Brute Force Permutations
If Arthur C. Clarke’s story The Nine Billion Names of God were true, then it seems rather pointless to plow through all 9,000,000,000 permutations to find one matching name. In fact, the exercise is more like a brute-force password cracking program than some celestial name search. What if the monks already knew the name? That would save time and effort.
Continue reading
Appreciation for Depreciation
Back in the day, computer programming courses offered predictable assignments. These were number-crunching exercises, which had little flash and, yes, were boring. Today you can plot graphics, manipulate sound, and explore the web with your code. Back then, you’d do something dull like calculate depreciation.
Continue reading
Permutations
In his 1953 short story, The Nine Billion Names of God, Arthur C. Clarke writes of Tibetan llamas who seek to know all the names of God. They’ve been writing down the names for centuries, but upon the advent of the computer, they enlist western science to help them finish the task in days. You can complete the same task with your computer and the C programming language, but in hours instead of days.
Continue reading
Slicing Strings with strsep()
The strtok() function is the traditional C library routine used to slice up a string. It has its limitations, however, so a more recent function was included in the library on some compilers to replace it: strsep().
Continue reading
String Parsing with strtok()
A handy tool for slicing up a string of text into chunks is the strtok() function. If you understand the strtok() function, it helps you better understand how more complex parsing functions work.
Continue reading