The four standard data types in C programming are char, int, float, and double. A fifth type is void, which is used to declare storage of an unknown type. My goal is to see how badly I can abuse this data type.
Continue reading
Category Archives: Lesson
Using the epoll() Function to Scan for Standard Input
As with the select() function covered in last week’s Lesson, you can use other networking functions to scan for pending standard input while a program otherwise spins busy. The epoll() family of functions allow for such monitoring.
Continue reading
Reading the Keyboard Queue ala Networking
A network program monitors one or more file descriptors (such as sockets) for activity. It reacts when information is ready to process. This technique can also be applied to keyboard input, though not as elegantly as the kbhit() function shown in last week’s Lesson.
Continue reading
Looking for a Keyboard Hit
The C language is famously platform independent. This feature may seem unimportant these days, but back in the early computer era having a language you code code on multiple systems was key to the C language’s success. This benefit may be one reason why C lacks a specific function to check on the keyboard status to determine whether a key has been pressed. Such a function is hardware-dependent.
Continue reading
What’s Next, Keyboard?
Suppose you must write code that remains busy while checking to see whether a key has been pressed. The program repeats a loop, performing various tasks, but eager for that key press. When a key is pressed, the code fetches the key. Two things stand in your way to make this happen.
Continue reading
Squaring a Value
The C language lacks an operator that squares a value or, more generally, raises a value to a specific power. To do so, use the pow() function. Yet I’m finding the need for a square() function as I explore some interesting and obscure mathematical thingies.
Continue reading
The alloca() Function
Any memory allocated in a function is retained when the function leaves, unless you first free it. This rule applies to all memory allocation functions — except one.
Continue reading
Fun with switch case, Part II
In last week’s Lesson, I reviewed the switch-case structure and how declared constants aren’t truly the kind of constant a case statement requires. This week I continue my exploration of switch-case, with an interesting and surprising quirk of the default condition.
Continue reading
Fun with switch case, Part I
The switch-case construction, or switch statement, provides your code with a decision tree that both easy to read and to debug. This construction is a bit daunting for the beginner, but becomes more familiar as you use it. It’s not without its quirks.
Continue reading
Creating Your Own Environment Variables
Programs use environment variables, thanks to the getenv() function shown in last week’s Lesson. They can also create their own environment variables, reset variable values, and remove variables.
Continue reading