The C language holds the potential of being utterly terrifying, which is something I admire greatly. Many beginners, as well as foolhardy travelers from other languages, treat a lot of the C language constructs as absolutes when, in fact, they aren’t. Therefore I present this week’s Lesson, the first in an ongoing series about strange, beautiful, and frightening things in the C language.
Continue reading
Category Archives: Lesson
More Heavily Weighted Random Numbers
One area where weighted random numbers come in to play is when doing a simulation. In a recent set of Exercises (May and June 2015), your mission was to craft a bowling game simulator. Like most simulations, the bowlings game simulator made use of random numbers. The problem in this situation is most decent bowlers don’t roll randomly.
Continue reading
Weighted Random Numbers
Random numbers are useful when simulating information and they add a degree of unpredictability to computer games. The problem programmers run into, especially with simulation, is that not everything is truly random. In many cases, some numbers need to be more random than others. The solution is to generate weighted random numbers.
Continue reading
Random Numbers with Decimals
The rand() function returns a pseudo-random number as a long int value. That value helps your code generate random numbers in the long int range. It can also be manipulated to yield random real number values, but that process involves . . . math.
Continue reading
To Form a More Perfect union
Next to enum, one of the more curious C language keywords is union. It’s tremendously unpopular. I would offer that it’s also not needed, but no one is talking about deprecating it.
Continue reading
The Mysterious enum Keyword
They’re the orphan keywords, urchins, unwanted, unused, unloved. Of the 32 C language keywords, a handful are seldom used. These include: auto, enum, register, union, and volatile.
Continue reading
A Fork in Your Code
All of the code I’ve written in my books as well as demonstrated on this blog has been single-tasking: The program runs as one process, does one thing, in order, and then terminates. With this Lesson, that streak ends.
Continue reading
Know Your Process
Program. Software. Application. Process. These are all terms that describe different aspects of a similar thing.
Continue reading
The Marvelous popen() Function
To launch and run another program from within your code, use the system() function. When your code must examine or save that program’s output, use the popen() function.
Continue reading
Execute and Leave
The system() function allows you to run one program from within another. If it’s your desire to launch another program and have your program quit, you can immediately follow system() with an exit() function. Or you can go out of your way and use the oddball execl() function.
Continue reading