Tag: programming

Practice Problem: Ending with a Newline

Let’s consider a text file: maybe it ends with a newline character, or maybe it doesn’t. Tools like git work more smoothly with files that end in newlines. Command-line tools like cat also produce clearer output when working with files that end in a newline. So, today’s Java programming problem asks you to fix files that don’t end in a newline.

Practice Problem: Circular Linked Lists

Linked lists are a topic I frequently discuss with students. So for this month’s blog post, I want to present a linked-list practice problem. We’ll look at a variation on the traditional singly-linked list, called a singly-linked circular list with a tail pointer. How can we insert into this type of list, and how can we search one for a given value?

What’s That Tiny Makefile?

When I’m working with programming students, I usually write a quick Makefile. Only a few lines long, this file allows us to recompile code on the command line just by typing “make”. In this post, we’ll skip over all the details of writing complex Makefiles. Instead, we’ll see how to slap together a rudimentary Makefile in seconds — one that will save us time while we’re working on an assignment.

Using C Defines to Change Constants During Compilation

It’s not uncommon that we find ourselves repeatedly editing our code and recompiling, just to change the value of a constant. In C, though, we can skip the step where we edit the source file to change the constant’s value. Instead, we can use a combination of the #define and #ifndef preprocessor directives to change its value directly on the command line at compile-time.

Exiting on malloc(3) Failure

To the annoyance of many students learning C programming, allocating memory by calling malloc(3) can fail. When it does, malloc(3) will return NULL. But, what should our program do when a call to malloc(3) fails? The question that today’s blog post explores is: when is it okay for our program to exit(3) — that is, simply terminate — because of a memory-allocation failure?