When the C Lords banished the gets() function into obscurity, cohorts of confused coders descended upon the fgets() function as a viable alternative. Alas, fgets() isn’t without its faults.
Continue reading
Category Archives: Lesson
A Foolish Way to Read a String
Back in the old days, the obvious and logical way to read a string was to use the gets() function, where gets stands for “get string.” That makes sense, but only a hardy fool would use that function today.
Continue reading
Just Keep Asking
As you frist explore programming, you may find yourself presented with a common puzzle: How to fetch proper input from a stubborn user. The solution is something I call the Just Keep Asking loop.
Continue reading
The Factorial Recursion
It’s the example of recursion most often used, but it’s not the best example. Of course, to illustrate a better example you need to approach concepts such as fractals and graphical programming doodads. My favorite form of recursion is traversing a directory tree. Regardless, the code for a factorial recursion remains the go-to workhorse.
Continue reading
An Example of Recursion
A recursive function calls itself. That’s a strange and beautiful concept, one that saves a lot of coding time, but how does it really work?
Continue reading
Introduction to Recursion
It’s truly a scary thing: A function calls itself. This trick can be done without damage to the space-time continuum, and nothing explodes when it’s done correctly.
Continue reading
Functions in Functions!
For an argument, functions in the C language can take literal values, equations, the result from another function, or any combination of these items. It’s a feature that’s both flexible and confusing.
Continue reading
How a for Loop Works
I received an interesting question the other day. A student asked me to explain a for loop. Dutifully, I set out and gave my description, which he found entirely baffling. So I backed up again and gave this explanation:
Continue reading
ASCII Programming Tricks, Round II
You probably don’t even think about it. How do the toupper() and tolower() functions do their magic? Both functions take a letter of one case and convert it to the same letter of the opposite case. They don’t touch any other characters or symbols.
Well, how would you code it?
Continue reading
ASCII Programming Tricks, Round I
The clever organization of ASCII character codes lends itself to some useful programming tricks. One of those tricks involves converting from character codes ‘0’ through ‘9’ to integer values zero through nine.
Continue reading