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
Category Archives: Lesson
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
Hello, Environment
The operating system keeps several variables in memory, variables that hold information necessary to running the computer. For example, the path variable lists directories in which the operating system looks for programs. The prompt variable describes how to display the command prompt. Some programs even create variables, allowing the programs to save configuration or other information.
Continue reading
What’s the sizeof That?
When writing a structure to a file, you need to ensure that you specify the proper structure size. The sizeof keyword is obviously the way you determine the size, but what exactly are you getting the size of?
Continue reading
printf(“Hello world!\n”);
Welcome to the C For Dummies blog.
Continue reading