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
Author Archives: dgookin
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
Declaring Structures, Trick #1
I refer to structures as “multi-variables” in my books and courses. Like a mini-database, they hold different data types and values, all bundled into a single unity. Structures form the basis of important programming concepts such as a linked list. Further, you can use structures to cheat and return multiple values from a function. As much as I dislike admitting it, structures are fun.
Continue reading
More Than One String in a String
I’ve seen some oddball constructions in C. You may have as well, especially if you enjoy reading obfuscated C. Yet, the weirdness I just witnessed came from an online C course I was browsing. I’d never seen it before.
Continue reading
Trigraph Sequences
I doubt you’ve ever used a trigraph. If you saw a trigraph in some C code, you might assume it was a typo or, from the early days of telecommunications, a modem burp. But trigraphs present a legitimate if not arcane way to represent certain characters, a holdover from the days of teletype input and primitive, barely-ASCII keyboards.
Continue reading
Misused Placeholders
I received a question from a reader about improperly specifying a printf() placeholder. Specifically, he used %d
(decimal integer) to output a string. Most compilers flag this condition as a warning, mismatched types or something similar. Still, the program is created and it runs. What does the output mean?
Continue reading