It was weird when I first saw it: A conditional expression used to determine a value. It sounds odd, but it works.
Continue reading
Category Archives: Lesson
Outputting an Unterminated Buffer
Properly formed strings in C are terminated with the null character, \0. Accept it or die!
However . . .
Continue reading
Desperately Freeing Allocated Memory
The critical issue about allocating and then freeing memory is to avoid a memory leak. This condition happens when a memory chunk gets lost, leaving the it lingering in RAM not doing anyone any good. Most often a memory leak occurs in a function.
Continue reading
Freeing Allocated Memory
One criticism I receive is that my code examples, from both my online training material as well as in my C programming books, fail to free any allocated memory before the program quits. This assertion is correct, and I have a darn good reason why!
Continue reading
Color Text, Part II
From last week’s Lesson, I showed how ANSI codes are used to set color text in terminal output. It’s time to go nuts showing the possibilities.
Continue reading
Color Text, Part I
Your C programs’ text output need not be so dull. Aside from adding wide characters, you can spice things up with color text. The terminal flavor is what determines the color palette. All you need to know are the secret codes that activate and deactivate the attributes.
Continue reading
Accessing the Printer in C
Back in the old days, the printer was a device wired to the computer and handled directly by whatever program wanted to use it. Printing in C involved opening the printer device and sending the data. Today, things work differently.
Continue reading
Initializing a Buffer – Your Own memset() Function
As I wrote in last week’s Lesson, the C23 standard renders the memset() function — a standard C library function for over 30 years — obsolete. If you want to initialize a buffer, you can use the secure memset_s() or just initialize the buffer manually or with your own memset()-like function.
Continue reading
The Perils of the memset() Function
While researching the upcoming — and significant — C23 version of the C programming language, I learned something surprising: The memset() function will be deprecated. It effectively does nothing when used in the C23 standard. The reason makes a lot of sense.
Continue reading
How Many Characters Output – So Far?
I doubt any C programmer has memorized all of the printf() function’s placeholders, options, and settings. It’s a character salad of interesting and weird things. One of the strangest has to be the %n placeholder.
Continue reading