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
Author Archives: dgookin
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
Which is Greatest? – Solution
The task for this month’s Exercise is to write a function, greatest(), that returns the largest of three values. While this task could be done easily with an if-else construction, the second part of the challenge is to write the entire thing as a single ternary statement. How’d you do?
Continue reading
Dumping the Screen in Color
The hexdump utility is a marvelous tool for grabbing a sneak peek at a file’s innards, especially when debugging code that performs file access. As a text mode tool, however, it could stand to use some colorful character improvement.
Continue reading
Which is Greatest?
Difficulty: ★ ★ ★ ☆
One of the first functions many C programmers code is max(). It returns the largest of two values. Though this operation can also take place by using a simple if-else comparison, it’s a great way to teach how functions work and test various comparison operators. But this task isn’t the challenge for this month’s exercise.
Continue reading
Consistently Constant
A new keyword added with the C23 standard is constexpr. It’s a storage class specifier that sets a constant value. Unlike the original C language qualifier, const, storage declared with the constexpr is truly constant and cannot be altered, as was demonstrated in last week’s Lesson.
Continue reading
Constantly Complaining
The C language has an issue with constants. As far as I can tell, three different ways are at your disposal to express a constant: constant expressions, literal constants, and constant types. More variety may be available, which adds to the confusion.
Continue reading