At 205 lines of code in last week’s Lesson, my memory-file project is getting larger by the day. At some point, the source code files must be broken out into separate modules, then compiled and linked separately. This is how I handle all large projects when it becomes too unwieldly to edit everything in a single file.
Continue reading
Author Archives: dgookin
Enabling Random Memory-File Access
The two types of file access are sequential and random. Sequential access means the file’s data is read from beginning to end, one byte after the other. Random access isn’t random in the sense that it’s haphazard. No, random access means you can read data from any position in the file: beginning, middle, or end.
Continue reading
Reading and Writing to Memory-Files
Opening and closing a memory-file is just academic. To make the whole shebang work, you must be able to read and write data.
Continue reading
Finding Characters – Solution
The challenge for this month’s Exercise is to write the charcount() function, which returns the number of characters in a string. The character matches exactly, so don’t worry about checking uppercase and lowercase differences.
Continue reading
Opening and Closing Memory-Files
To treat a chunk of memory as a file, it must be “opened” and a handle returned for future file reference and interaction. Likewise, the memory-file must be “closed” when you no longer need it. To accomplish these tasks, I’ve crafted the mem_open() and mem_close() functions.
Continue reading
Finding Characters
Difficulty: ★ ★ ☆ ☆
When I was working on last month’s Exercise, I scoured the C library for a function that returned the number of specific characters found in a string. The closest I could find was strchr(), which returns the location of a given character in a string. You can set this function in a loop to find subsequent characters, but what I needed was a tally, a total count of all matching characters in the string.
Continue reading
Memory Files
In the Unix environment, everything is a file. For example, you can open the terminal as a file, which I covered in a previous Lesson. But what about memory? Can you open memory as a file? And why would you want to?
Continue reading
The camelCase to snake_case Conversion with Proper Memory Allocation
With all the storage available in a modern computer, it’s easy — and often perfectly okay — to be overly generous when allocating memory. Still, the old coder in me has a lingering desire to save every byte possible. So when it comes to crafting a solution for this month’s Exercise, my desire is to be byte stingy.
Continue reading
A Better camelCase to snake_case Conversion
My solution for this month’s Exercise took some terrible assumptions. First, that the strings are merely output and not stored. Second, that the strings are perfectly formed camelCase and snake_case. In this Lesson, I address the first concern.
Continue reading
From camelCase to snake_case – Solution
The challenge for this month’s Exercise is to convert a name from camelCase to snake_case and vice-versa. As usual, several approaches provide a possible solution. The directions were to output the results and not store them, so my solution is rather simple.
Continue reading