# Linux and C – “Hello, world!”

Since the release of K&R, every programmer has become familiar with the Hello, world! program. I find that learning to build this program from start to finish is an excellent introduction to the tools available in Linux. Setup First, we want to create a directory for our programs. I recommend ~/Documents/Programming, because this is a simple

# Linux + C – Looping

Almost every useful program requires loops and tests, which determine how the program will proceed. Without this feature, a program might as well be a text file, which generates its contents on every execute. There are three basic loops which we generally recognize. The for loop sets an initial condition when we enter the loop, then

# Linux + C – Doing the Math I

If we're being honest, we don't start programming because we want to print out clever one-liners to a terminal. We want to calculate something complicated or massive, and we want to do it quickly. Variables, functions, and symbols We all know what a number is, right? We may behind many countries in mathematics and science, but

# Linux + C – Doing the Math II

We've looked at the basics of performing basic math in C, but there are a few more things we should discuss before we write any code. Data Types We know that there are many different kinds of numbers. For example, we have signed numbers (which can be positive or negative) and unsigned numbers (which are assumed

# Linux + C – Characters and Strings

It's time to delve into one of the enormously useful topics of programming: working with text. Characters and Strings In the past few programs, we've used the printf() function quite a bit. This magical little function generates strings and prints them to the terminal. But what exactly is a string? First, we have to understand what a

# Linux + C – Arrays

Let's be honest, folks. We don't expect to work with a few clearly defined variables forever. Sometimes we need to handle a lot of things at once, or at least a group of related things. The simplest method for lumping a group of things together is the basic data array. Arrays An array is a set of

# Linux + C – Formatting

At this point, we've written and compiled a few C programs, and I'm sure you're already noticing the patterns. Still, it sometimes helps to have these patterns clearly defined. One Line When we talk about a line of code, we don't necessarily mean one physical line on the page. A line of code is one logical

# Linux + C – Adding Arguments

It's finally time to look at those arguments we pass into main() - int argc and char *argv[]. Terminal Arguments You might have noticed that vi and gcc are both programs. You might also have noticed that we always call these programs with arguments. You might also notice that, up to this point, we haven't called any

# Linux + C – Reading from stdin

We know how to send input from the terminal. Now we'll look at the right and wrong ways to do keyboard input within your program. Reading Input from Standard Input Have you ever seen a program which used a prompt to ask for something? For a simple case, it could look like this: Username: >> Password: >> There are numerous functions

# Linux + C – Manipulating the Precompiler

Ever wondered what the whole #include thing really means? Of course you have. Precompiler There are basically three stages that gcc goes through when it compiles your program: precompilation, translation, and linking. At this point, we're interested in that first stage. The precompiler is the program which reads and organizes your C code for the translator to