Sometimes I turn off my programmer brain and look at code to admire it in an innocent way. At first glance a C program source code file looks poetic, using the same patterns and flow. Code is also cryptic, which inspires many programmers to try to invent a new way to do something in a charming and confusing manner. One of my attempts was to rationalize this expression: ++a++
Continue reading
Category Archives: Lesson
Optimizing My Code
One of the burdens of being a programmer is that few people are witness to your brilliance. You can write the keenest code since the Countess of Lovelace and it’s likely no one will ever appreciate your genius. But don’t let this limitation stop you!
Continue reading
Merry Pointer Mischief
Nothing paralyzes a C programmer like double-asterisk notation. What does it mean? Can you use it? How is it passed to a function and then referenced? I, too, fall victim to this confusion. So a good explanation is in order.
Continue reading
More ANSI Code Cursor Manipulation
C is stream oriented, but in a terminal window you can use ANSI commands to provide more control. These commands can change text color as well as manipulate the cursor’s location, as covered in this month’s Exercise solution. The manipulation isn’t over yet!
Continue reading
Erasing Text for Stream Output
One of my first programming obsessions was online communications. I wrote several modem programs for the TRS-80 (in Z80 Assembly) and then moved to the IBM PC/MS-DOS where I coded communications programs in both Assembly and C. I learned a few things.
Continue reading
A Grid of Random Stars, Part VII
The final (and merciful) update to my Grid of Random Stars program involves two major changes. First, because I call the update_grid() function only once, it can be incorporated into the main() function, no program. Second, I remove pointer notation.
Continue reading
A Grid of Random Stars, Part VI
The program may output what I want, but the code isn’t done yet. Continuing from last week’s Lesson, I’d like the program to output a single grid showing a summary of all the rectangles found. This update requires more changes to the existing code.
Continue reading
A Grid of Random Stars, Part V
The two problems I recognized in the code from last week’s Lesson were that scan_column() and find_right() don’t need to be separate functions. Also, the code fails to find all the rectangles in the grid, which is bad. Time to fix the code!
Continue reading
A Grid of Random Stars, Part IV
I was so excited with last week’s code that I didn’t bother to confirm that it worked properly. No, I was eager to see graphic output of the found rectangles.
Continue reading
A Grid of Random Stars, Part III
The next update to my pattern-finding program is to hunt down and find a clutch of asterisks in the grid that form a rectangle. Figure 1 illustrates what I’m after.
Continue reading