The process of opening, reading, writing, and closing files is basic C language stuff. For specific details about a file, the stat() function is used to fill a stat structure. Unfolded are the nitty-gritties about the file itself, such as its size, ownership, and up to four time-date stamps.
Continue reading
Author Archives: dgookin
When There is No π
Reader Chris pointed out a fun and common C language inconsistency in last week’s Lesson: The constant M_PI isn’t always available. It’s not defined as part of the C standard, which means your compiler may lack this handy shortcut, located in the math.h header file. What to do, what to do?
Continue reading
π Day
Mathematic geeks of the world celebrate March 14 as “pi day.” The logic is that the date is 3/14, which are the first three digits of the value π, or 3.14159….∞
Continue reading
Increasing Brightness – Solution
The challenge for this month’s Exercise is to fill a cup without overflowing it. That cup is an unsigned char value, which goes only to 255 maximum. If your goal is increase the value of an unsigned char variable by 10 percent, any value over 255 - (255/10), or 220, must be set to 255.
Continue reading
From the C Relic File: auto
Of all the C language keywords you don’t use, auto is probably the most memorable. That’s because it’s listed first among the canonical table of 32 C language keywords. Yet, in all the code you’ve written or seen, auto is seldom used if at all. So what does it do and is it even necessary?
Continue reading
Increasing Brightness
Recently, I did some graphics programming. The task I gave myself was to highlight a JPEG by drawing a box around an interesting part of the image. The puzzle was which color to make the box so that it would stand out.
Continue reading
Variable Width Values in Conversion Characters
The topic of conversion characters, or printf() percent placeholders, is vast and confusing. Most programmers know the basics, but the details are so complex that some handy shortcuts are overlooked. One of those shortcuts is the * wildcard that sets width values.
Continue reading
More Fun with _Bool
Plenty of C coders implemented boolean variables long before the C99 standard introduced the _Bool type. Programmers defined TRUE and FALSE constants, they used char or short variables as toggles, or they manipulated bits in a byte to simulate binary and boolean operations. With all that going on, you’d think adding a boolean variable type to C and calling it bool would have been a no-brainer. It wasn’t.
Continue reading
Ruminations on the _Bool variable type
One of the C language keywords added in the C99 update is _Bool. It’s an underscore keyword, which means it lacks the respect gained by the other keywords — even the useless ones like auto.
Continue reading
Oscillation – Solution
For my solution to this month’s Oscillation Exercise I created a toggle variable. This variable switches between 1 and -1. It sets the direction for the cascading values.
Continue reading