I recall the math class where negative numbers were introduced. I was appalled. From Star Trek, I easily accepted the concept of antimatter, but the notion of negative values deeply offended me.
Continue reading
Author Archives: dgookin
Balancing Accounts
Difficulty: Medium
Your bank receives two deposits or credits and three bills or debits. The credits cover the debits, meaning that your balance should never go below zero, but the bank has clever software: The bills are calculated first, which thrusts your account into negative territory complete with fees — even though the deposits cover the bills. Is this obnoxious behavior the result of greedy bankers or clever programming?
Continue reading
Options for the strfmon() Function
The strfmon() function, introduced in last week’s Lesson properly formats a monetary value for specific regions. To unlock the function’s various features, you must understand and use formatting placeholders.
Continue reading
Exploring the strfmon() Function
The C programming language doesn’t sport the thousands of functions (or methods or what-have-you) available in Java. They say Java programmers may never use or even know the variety. With many fewer functions available in the standard C library, I would think to know them all. Then along comes another one I’ve neither used nor heard of. This week’s Lesson covers such as function, strfmon().
Continue reading
An Update to My strcasecmp() Function
Many moons ago, I wrote about the non-standard function, strcasecmp(). It works like the C library function strcmp(), though it ignores character case. Turns out my return value from the function isn’t exactly correct.
Continue reading
Positive, Negative, or Zero – Solution
Your challenge for this month’s Exercise is to write a sign() function, which returns 1, 0, or -1 depending on the sign of an integer. A relatively simple thing to code — I hope!
Continue reading
Manual time_t Values and Time Zones
The 16-hour puzzle presented in last week’s Lesson has been resolved: It was actually a 24-hour puzzle, minus 8 hours for my time zone, which equals 16 hours. But what can be done about the time zone difference?
Continue reading
Positive, Negative, or Zero
The strcmp() function returns a value based on the comparison of two strings. The value is zero when the strings match, otherwise the value is positive or negative depending on how the strings compare. This result makes me wonder which other functions can return positive, negative, or zero values and whether the C library has a sign() function or similar that helps make such a determination.
Continue reading
The time_t Value . . . and 16 Hours?
In last week’s Lesson, I covered the mechanics behind manually calculating a time_t value. My code was successful, but in a curious way.
Continue reading
Creating a time_t Value
Ho boy! This time_t project turned out to be a lot more complex than I thought it would be!
The problem: Count the number of seconds elapsed from January 1, 1970 to a given year, month, and day. This task is easy for a computer, but not that easy to code if you want to get the value correct.
Continue reading