A good way to exercise your C programming muscles is to work on a encoding/decoding project. This process makes you think about data and how it’s represented, and also how to work on both ends of an input/output puzzle.
Continue reading
Category Archives: Lesson
On-the-fly Variables
Traditionally, a C program announces its variables at the start of a function block. The variables are presented by type and name, and they can be initialized at that time as well. This tradition isn’t a rule, and many C programmers break it.
Continue reading
Reading a File Randomly
Random file access isn’t about generating a random value and then reading at that position in the file. While you could do that, the term random access refers to file access that isn’t sequential. I suppose they could have called it dynamic file access, but I was only 8-years-old when computer scientists developed these concepts, so my input would not have been welcome.
Continue reading
Abuse the File Position Indicator
Files can be read sequentially or you can hop around, reading this chunk or that chunk, which is how random file access works. Internally, however, it’s all just file access. The difference between sequential and random file access is how the file position indicator is abused.
Continue reading
More File Access Messing
In last week’s Lesson, I covered the ftell() function, which returns the current file position indicator. That indicator can be manipulated, allowing you to control how a file is read in a non-sequential way.
Continue reading
Messing with File Access
Like reading a book, sequential file access starts at the file’s beginning (or top) and reads bytes one after the other until the nefarious EOF is encountered. You probably don’t think about how that works, and you don’t need to. The operating system handles the job of reading a file; your C code is simply along for the ride.
Continue reading
To Increment Before or After
Say you have a for loop that increments one notch each time it repeats. I code such a loop in this fashion:
for(x=0;x<10;x++)
More common, however, programmers use this approach:
for(x=0;x<10;++x)
The difference is in how the variable x is incremented. I put the ++ after the x, but most coders put it before. What the deal?
Continue reading
Skipping
Of the two C language keyword looping statements, for is the most traditional and probably the most popular. It’s also the most frustrating for beginners because of its many parts. But eventually, a comfort level arises with using the for loop, which is sad because it’s more powerful than a simple counter.
Continue reading
C Language Neat Tricks #2 (Part II)
You could call it a neat trick or just something so oddball insane that few programmers would dare breech the territory: A variable that holds the address of a function; a function pointer.
Continue reading
C Language Neat Tricks #2 (Part I)
Like a variable in the C language, a function has an address — a location in memory. This fact shouldn’t be surprising to you. After all, the function has to sit somewhere. And my guess is that location doesn’t change as the program runs.
Continue reading