The C language lacks an exponentiation operator, which would raise a base value to a certain power. For example: 2^8, which in some programming languages is an expression to raise 2 to the 8th power. Instead, C uses the pow() function.
Continue reading
Category Archives: Lesson
The Perils of strncpy()
Always be careful when manipulating strings! Tack on that null character, '\0', at the end of a string! And don’t worry about the C language string functions: They perform this important feature for you. But do they all?
Continue reading
To Read a Chunk a Data
Say you must read 2048 bytes from a file. Which of the following fread() statements works for you: A, B, both, or neither?
A. c = fread( buffer, 2048, 1, fh);
B. c = fread( buffer, 1, 2048, fh);
Continue reading
Old Habits Die Hard
Like doing anything for a long period of time, I find myself often using the same approach to solving a programming puzzle. It’s habit. It’s tradition. And it often hinders my insight into the language.
Continue reading
Slicing Words from a String
The fall-through effect of the switch-case structure can be extremely useful, as demonstrated in last week’s Lesson. For slicing words from a string, you can easily match multiple word separators, saving you from coding complex statements or weirdo if-else structures. But a problem arises when multiple word separators appear.
Continue reading
Falling Through a Switch-Case Structure
C language keywords often used in a switch-case structure are switch, case, default, and break. Only switch and case are required. You can omit the default condition. And the break keyword is used to avoid execution falling through the structure, yet sometimes that may be a useful effect.
Continue reading
Switch-Case Execution
The switch-case structure is the most complex decision tool in the C language. Yes, the ternary operator is more cryptic, but a proper switch-case structure involves more keywords: switch, case, default, and break. The break keyword is what I feel makes the structure most interesting.
Continue reading
The Cryptic Text Encoder
In last week’s Lesson, I waxed on about how a text message can be concealed in a delightful manner, making it not look like a text message at all. To get to that point, you must write some code that translates plain text into the values desired.
Continue reading
Cryptic Text Encoding
Typing in sample code was all the rage back when I first learned assembly language. The programs were short. Most of them I could understand based on my limited knowledge, but I still enjoyed seeing the result and wondering how they did it. Hopefully, I’d learn something.
Continue reading
Long Lines
If I were well-versed in a handful of programming languages, I’m sure I’d find one better than C for examining line lengths in a text file. Perhaps Perl could do the trick? or even the shell language? Regardless, I know C.
Continue reading