Linux + C – Structures, Switches, and Your First Header

This will be a bit of a longer section, because I couldn't think of a fun way to write the code otherwise. Bonus! Structures A structure is a data element defined by the programmer which contains several member data elements. We define these structures to allow ourselves to handle a set of related data much more

Linux + C – Introducing Pointers

You've likely noticed the * symbol showing up in our code. Time to look at what that means. Value and Reference There are two kinds of data in a program: values, references to a value. We already know how to create a value object, because basic data types such as int and char are value objects.

Linux + C – Arrays as Pointers

We've dealt with arrays a little bit in the past. Did you know that that whole time, we were dealing with pointers? Array as a Pointer When we declare an array, we are really doing the following things: Allocating a section of memory large enough to contain N objects of the chosen data type Creating a pointer to

Linux + C – Linked Lists are Applied Pointers

We now understand (at least a little bit) how we can work with pointers. We're now going to look at one of the simplest, but most useful, data storage structures - the Linked List Referencing a Pointer Before we go any further, we need to look at a bit of syntax. We know that when we

Linux + C – Malloc and Free

In the last post, we employed dynamic memory allocation. Today, we're looking at that concept in further detail. Allocating Memory The function malloc() - memory allocate pulls a section of the heap - memory that exists outside of the usual program stack which is used to store data members - and returns it to you. The

Linux + C – Some other Facts about Pointers

Pointer Math Pointers are numbers, which means we can use math to change where they point. For example, in an array we store the pointer for index 0, then add to it in order to find the later indexes. For example, if we store a uint32_t (32-bit integer) array at the address location 0x8FFFFF00, the

Linux + C – File Pointers

Now that we have a basic understanding of pointers, we're ready to look at file I/O. Files A file is a collection of data which is stored in main memory (as opposed to registers, cache, or RAM). These files are capable of storing a tremendous amount of data, which we can retrieve and manipulate with our

Simplicity of C

I have a copy of Bjorn Stroustrup's Programming: Principles and Practice Using C++ (2nd Edition). That's a book about C++, written by the guy who developed C++. It's over 1300 pages long, and it only covers the most basic details of the language. It calls on a magic library, for crying out loud. I also

Linux + C – Wrapping up the Programming for a Bit

So far, the vast majority of this series has revolved around programming in C. We have covered: Writing our first program Basic Loops The theory and execution of math in C Creating and printing characters and strings Working with arrays The basic rules of C syntax Programming with Command Line Arguments Safe and unsafe string operations (when reading from the terminal) How to

Linux + C – Welcome to the Terminal (And the File System)

With this little box, you can do almost anything. Hotkeys There are a few quick commands you will need to know as we move forward with the terminal. In no particular order: CTRL-C - Close the process currently running. This is sort of like pressing the X on a GUI interface. CTRL-Z - Kill the process currently running.