It’s easy for a good C programmer to code a program to tally the number of unique words in a chunk of text. Further, the computer could track repeating words. This task would drive a human nuts, but a computer? No problem.
Continue reading
Author Archives: dgookin
Encoding a String – Solution
The task for this month’s Exercise is to write an encoding filter that follows a specific pattern: After the first character (or byte) is output as a 2-digit hex value, the remaining characters are output as the difference between the previous character and the current character. I’m sure this type of encoding has an official name, but it’s the holidays and I’m too lazy to look it up.
Continue reading
Parsing Words with the strspn() Function
I’ve dabbled on the topic of parsing words from a string several times on this blog: Slicing Words from a String, Parse and Count Words in a String, and more. I just can’t have enough! In fact, this Lesson picks up the topic again, continuing my discussion of the strspn() and strcspn() functions from last week’s Lesson.
Continue reading
Encoding a String
Difficulty: Medium
Here is your message:
48190F0009A72827FDFDFBFD18FAAD460CFDFEB323EA192903BB1731F800FCFC0E97
Continue reading
The String Span Functions
When I scour the C for functions to assist my code, if often overlook a few that seem dull or confusing. One of those I’ve always glossed over is the strspn() function, as well as its counterpart, strcspn().
Continue reading
All Those _t Data Types
You see them often if you code in C: time_t, size_t, and other _t data types, usually specific to some function or library. The C gurus have a method to their madness when it comes to naming these variables. The _t stands for something. It’s very consistent on purpose.
Continue reading
Declaring Structures, Trick #3
Bitfields in a structure are weird, as I covered in last week’s Lesson. If you’re a nerd who appreciates bits and bit manipulation, you’re probably in love. These bitwise tricks are things the C language excels at. With a keen knowledge of bits, and a desire to use integer values beyond the standard widths, a nerd can have a lot of fun in C.
Continue reading
The Power Grid – Solution
I hope you didn’t find this month’s Exercise too difficult. I do occasionally like to toss in an easy one. But for me, the big task was getting the output just right.
Continue reading
Declaring Structures, Trick #2
In last week’s Lesson, I covered a trick you can use to assign values to structure members non-sequentially. It’s something you may rarely use, but a valid tool in your C programming tool chest. It’s also not the weirdest thing that can happen in a structure.
Continue reading
The Power Grid
Difficulty: Easy
I enjoy programming tables, rows and columns. The standard technique is to use a nested loop. In fact, when teaching nested loops, outputting a table is par for the course.
Continue reading