Sure, your programs can accept values from the input stream, but most of the time numeric input comes in the form of text. The issue then becomes how to transform the string “1234” into the value 1234.
Continue reading
Hi-Low
Here’s a brain puzzle for you: Write a function that accepts a numeric array and returns the high and low values from that array. Can it be done?
Continue reading
Say It in Binary
01010011011000010111100100100000010010010111010000100000
01101001011011100010000001000010011010010110111001100001
011100100111100100001010
Continue reading
Round Me Up, Round Me Down
The C language library features a few rounding functions, but most of them deal with trimming floating point values down (or up) to integers. The other day I encountered an interesting problem: How to round a value up or down to the nearest value of 5.
Continue reading
1st, 2nd, and 3th
For your June exercise, you need to concoct code that properly generates an ordinal number. Write a function that returns a string “st” “nd” “rd” or “th” that’s tacked on to any integer value from 1 through what-have-you.
Continue reading
Fixing fgets() for Input
The fgets() function is a marvelous tool for reading chunks of text from the keyboard or standard input. One problem I have with it is that it also reads the Enter key press, sticking a \n into the string. That’s not a big issue, however, because you can easily pull out that character.
Continue reading
The delay() Function
Most C programmers know the sleep() function, which pauses program execution for a given number of seconds. Seconds are a vast chunk of time, especially in a computer where things happen quickly. So a desire exists for a function that delays execution for smaller slices of time. For that duty you’ll need to code your own function, similar to the delay() function I use.
Continue reading
Error Message to stdout
The three standard I/O devices are stdin, stdout, and stderr. They represent the devices for standard input, standard output, and standard error messages. While you might see plenty of examples of stdin and stdout, examples of stderr are less common, although they don’t have to be.
Continue reading
Calculating a Unix Epoch Date
Before you can embark upon the frightening topic of Time Math, you need to convert dates and times into Unix Epoch time_t values. It’s not that difficult of a task, assuming that you can accept that time programming in C isn’t complex and rude, which of course it is.
Continue reading
Binary Bit Fun: |
May the 4th be with you! It’s Jedi day, or Star Wars day, or whatever. Here’s a binary puzzle for you, one which demonstrates how the bitwise OR operator can be used to set bits in an integer value.
Continue reading