This month’s Exercise is to create an array of six players, assign each a random score (1 to 100), then display the player’s scores by rank. The first problem you most likely encountered was how to keep the player’s number and score together.
Continue reading
Author Archives: dgookin
Behold the Stack, Part III
Whether you simulate a stack in your C code or just ignore the concept altogether, your program constantly uses the processor’s stack. Specifically, if the code contains a function, it uses this stack not only to call and return from the function, but to pass and return arguments as well.
Continue reading
Ranking Scores
In your fancy, new game, the program dutifully track players and their scores. When the game is over, or at the end of a round, the players not only want to know their scores, but where each sits in the overall ranking. That process takes a bit more coding than just spitting out the scores.
Continue reading
Behold the Stack, Part II
At the lowest programming level, you encounter machine code. This is the language of the processor itself. Machine code directs the processor to do things, such as read from or write to memory, store data, perform math, and other tasks. And if you dare to program a processor directly, you’ll encounter something called the stack pointer register.
Continue reading
Behold the Stack, Part I

One of those weirdo programming concepts university sophomore programming students eagerly avoid is the stack. It’s a type of storage with unique features, but it’s difficult to appreciate unless you understand its origins.
Continue reading
The abs() Function
Seriously, why do programmers need an abs() function? It’s available in just about every programming language; if you view an alphabetic list of functions, abs() is probably the first one. Yet, what’s the point of a function that simply converts negative values to positive values?
Continue reading
When You Need a Function – Solution
For my solution to this month’s Exercise, I crafted the ask() function. That’s because the original code prompts three times with a question string and an answer buffer, which is the repetitive part of the program I chose to cast into a function.
Continue reading
Yes, You Can Nest while Loops
Somewhere in my vast array of teaching material, I claimed that only for loops can be nested. That’s poppycock.
Continue reading
When You Need a Function
I believe two reasons exist for creating functions. The first is repetition; when you have a chunk of code that duplicates several times, it’s best to shove it off into a function where it can be called repeatedly. The second reason is readability.
Continue reading
A scanf() String Trick
I’m not a fan of the scanf() function, despite how handy it can be. It’s a great teaching tool, but for a program that accepts string input, you need to use fgets() instead. Still, scanf() can be used to read a string, providing that you know the whitespace requirements beforehand.
Continue reading