While writing some code recently, it became necessary to translate timestamp strings into time_t or epoch time values. This value is the number of seconds that have ticked since midnight, January 1, 1970. time_t values are stored long integers (generally), but I needed a utility to translate them into time strings. It turned out, such a tool wasn’t that difficult to create.
Continue reading
Author Archives: dgookin
The Leap Year Function – Solution
I’ve tackled the leap year program on this blog before. My Month Program series addressed the issue specifically. That code offers the february() function, which returns 28 or 29, depending on whether the current year is the leap year.
Continue reading
Multiple Expressions in a for Condition
Every C programmer has screwed up a for loop’s statement. Having three arguments in one set of parentheses is just begging for trouble. That’s a lot of yard waste, but there’s a reason for all the detritus.
Continue reading
The Leap Year Function
My brain’s algorithm for determining whether the current year is a leap year is based on US Presidential elections. They always happen on a leap year. Or do they?
Continue reading
Radians to the Rescue!
The word radian comes from radius, which is half the diameter of a circle. If you take a radius and create an arc along the circle of the same length, you get one radian.
Okay. So what?
Continue reading
What the Heck is a Radian?
Math should be fun. My observation is that it’s not taught correctly in school, so generations of students get an education, but are weak in math. I’m one of them. As I’ve aged, I’ve grown fond of math, but still struggle with it. That’s disappointing because so much of math is actually kind of cool, just not explained well.
Continue reading
Marching Through an Array in Memory
C language pointers are smarter than the old BASIC peek and poke commands. A pointer knows the the type of value it’s referencing in memory, specifically how large the value is or how many bytes of storage it occupies. You can use the Code::Blocks debugger to witness such pointer intelligence.
Continue reading
Translating a Timestamp – Solution
Your task for this month’s Exercise is to take a timestamp string and move values from inside a string (characters) into a structure. It’s not an easy exercise, and it doesn’t have a single, best solution.
Continue reading
Deep Inside RAM
In last week’s Lesson, the Code::Blocks debugger helped examine the values of two variables, short int a and short int pointer p. Pointer p revealed a memory location inside the computer, which you can examine by using Code::Block’s Memory dump window.
Continue reading
Translating a Timestamp
A timestamp is one of those tricky chunks of data that’s not really a single value. Often it’s a clutch of integers or — worse — it’s a string. To do time calculations on the timestamp, you must translate it into a more useful form.
Continue reading