The C library hosts many file and directory management functions. They’re all pretty standard, no matter which operating system you use. What isn’t standard, however, is the size of a pathname. That value plays an important role if you’re to properly allocate memory to store directory information.
Continue reading
Category Archives: Lesson
Finding the PATH_MAX
Your code may be compiled on a PC, Mac, Linux system, or even some microcontroller. In each case, it helps to know the environment before you code. You can guess, but it’s better to use the defined constants — if they’re available to you.
Continue reading
Know Your Limits
Back when I was a young, budding nerd, I popped off how there are always 8 bits in a byte. A much wiser programmer raised an eyebrow and quizzed me, “Always?”
Continue reading
Official C Library Rounding Functions
Nestled within the C Library are various functions mathematical, a handful of which are used to round floating point values. The most common of them are ceil(), floor(), and rint().
Continue reading
What is True?
It happens so often, I’m curious as to why the C language standard I/O header file doesn’t define TRUE and FALSE. Then again, what is TRUE and FALSE to a programming language — or to a computer? Why is this value true and that value false in the first place?
Continue reading
Yet Another Way to Cap an Array
You don’t know how many items the array might store, so you guess. Then the program fetches only n values, all in the range of –X through 0 to +X. How do you know when the valid values stop?
Continue reading
Averaging an Array of Unknown Size
Imagine you’re working with an array that has room to store thousands of integer values. You’ve been hired to craft a function that averages those values, but you don’t really know how many values are stored in the array. The guy who gave you the assignment (me), simply said that the array is capped with a zero value.
Continue reading
Capping an Array
Compared to other programming languages, C is weak when it comes to dealing with arrays. The array has a starting point and a variable type. That’s pretty much it. Your code determines where the array ends. That type of programming discipline terrifies coders of other languages.
Continue reading
The getline() Function
The latest and most trendy function for reading a string of text is getline(). It’s a new C library function, having appeared around 2010 or so.
Continue reading
Fetching Text
Seeing the limitations of the C library input functions, I set out a long time ago to craft my own input function. It does exactly what I need, which is the charm of writing your own functions — and the beauty of the C language because it gives you access to the low-level tools that allow for such play.
Continue reading