Bouncing a cursor on the screen is a fun programming exercise, and you can use common C library techniques and ANSI escape sequences to make it happen in a terminal window, as covered in last week’s Lesson. At this point, most programmers would be content and leave well enough alone. Not me!
Continue reading
Category Archives: Lesson
Bouncing an Asterisk
For last week’s Lesson, I gathered various techniques to show how the terminal screen can be manipulated directly in C without using a library like Ncurses. I have a few more tricks to show.
Continue reading
Playing with the Terminal
I miss the bad old days, back when I first learned to program. The microcomputers of the day were single user, single task. The hardware was directly accessible. You can truly do some messing around, which was quite entertaining for a budding programmer.
Continue reading
The Look-and-Say Sequence
(As Much as the Computer Can)
Coding a Look-and-Say sequence should be fun, just like any C programming project where you’re not under pressure from a deadline. From last week’s Lesson, I was able to create a nested loop that takes a number and outputs its Look-and-Say values. It’s time to update this code to output a sequence.
Continue reading
Coding a Look-and-Say Sequence
You may have seen this sequence on the Internet, in one of those “guess which number goes next?” type of posts:
1 11 21 1211 ...
So, which number comes next? I suppose it’s possible to divine a solution mathematically, but this sequence is known as a Look-and-Say sequence.
Continue reading
Modifying an Array
I’ve seen functions (okay, methods) in other programming languages that let you digitally tussle with an array. You can split an array, trim it, expand it, insert elements, remove elements, and so on. Such things are possible in C, but you must code the function yourself.
Continue reading
More Messing with Array Subscripts
I’ve written before about array subscripts and how they’re secretly expressions. But another weird aspect of array subscripts also looms on the horizon: The format a[1] can be written as 1[a].
Continue reading
Exploring Allocated Memory
Details about a pointer can easily be obtained and output: it’s name, address, and contents. Obtaining the size of the buffer it references, however, is a different animal.
Continue reading
The Art of Memory Reallocation
Clearing the pointer hurdle is a major leap to learning the C programming language. Using the malloc() function to allocate storage is central to grasping this concept. Then along comes the realloc() function, and minds are blown.
Continue reading
Hungarian Notation Rhapsody
The rules for naming variables, or identifiers, in C are simple: The names must start with a letter and contain letters and numbers. The _ (underscore) counts as a letter. Upper- and lowercase letters are considered differently. And only the first 31 characters are significant, though some platforms may extend this length.
Continue reading