
After I bought a mouse for my first PC, I set out to write a mouse-based program — a game. (The Microsoft Mouse manual came with the full API.) It was fun and challenging, as all programming tasks should be. Surprisingly, reading the mouse is also possible in a Linux terminal window — providing that you know the secret.
Continue reading
Direct Terminal Input
While raw terminal input allows standard I/O functions to capture uncooked text, another approach for reading the terminal may also capture a few uncooked morsels. This process involves using low-level file I/O commands. These functions are read() and write(), which are part of the POSIX standard.
Continue reading
Reading Raw Input
Switching between cooked and raw modes requires access to the terminal’s configuration data. In Linux, these settings are manipulated at the command prompt by using the stty ccommand. In a C program, you use various functions available in the standard library and defined in the termios.h header file.
Continue reading
Cooked or Raw?
When the waitress asks how I like my eggs, I answer, “Cooked.”
O, how we all laugh . . .
The humor here is that it’s assumed you desire your eggs to be cooked and the waitress’s question relates to the fashion by which the eggs are to be cooked: fried, over-easy, sunny-side-up, scrambled, poached, and on and on. But the question of cooked or raw also applies to standard input for a computer terminal.
Continue reading
Is It a “Real” Triangle? – Solution
The challenge for this month’s Exercise is to generate three random values and determine if they work as sides of a valid triangle. To make this determination, you must consider three types of triangles and test the generated values for each.
Continue reading
Getting and Setting the File Position Indicator
As data is read from a file, a file position indicator (which most C references call a “file pointer”) moves sequentially through the file’s data. As a review, three functions are available to adjust this offset:
Continue reading
Is It a “Real” Triangle?
Difficulty: ★ ★ ☆ ☆
Back in October, the C programming Exercise was to code Heron’s Formula. The challenge required the user to input three values, one for each side of the triangle. But, as I learned since, a triangle must have specific side length ratios for it to be a valid triangle.
Continue reading
A Colorful Hexdump
By combining the code page 437 data from last week’s Lesson into my colorful hexdump utility, I’m finally able to wrap up the code and produce a program that outputs a more interesting file dump.
Continue reading
Code Page 437
The one common denominator in the microcomputer era was ASCII. These 128 codes (zero through 127) provided a modicum of consistency for text files shared between the abundant computer platforms from days of yore. But a byte (char) holds 256 values. So what was done about those non-ASCII character codes, 128 through 255?
Continue reading
Dumping the Screen in W-I-D-E Color
Updating the hexdump utility with color is good, but adding wide characters for output is even better. From last week’s Lesson, I’m adding wide character output to generate codes for non-printing ASCII values 0 through 31 and 127.
Continue reading