Part 1. Let’s learn coding

Why C?

In this video series, we'll learn about how to write FreeDOS (and Linux) programs, in C. You may ask why learn C, and not some other language like Assembly, Pascal, or Basic? Or a more modern programming language like Java, Go, or Python? There's actually several reasons to learn C instead of these other programming languages:

  1. C is a fairly straightforward language
  2. C produces very tight, efficient code
  3. If you learn C, you will have a good starting point for other programming languages like Go or Java

That last point is important. C is a very old language (around 1972) and has remained popular ever since. In part due to C's success, lots of other programming languages "borrowed" syntax and other elements from C. So if you learn C, you'll have a very good starting point to learn other languages like Java, C# (.NET), C++, JavaScript, PHP, Go, and a bunch of other programming languages.

And you'll be able to write your own programs and games! In fact, throughout the series we'll learn about C by writing programs.

About the video series

This series will give you a good introduction to C. Think of this as a "C Programming 101" self-learning course. If you follow along with the videos and with the materials here, you should have a great grounding in C when we're done.

Throughout the video series, we'll learn how to write programs in C. At first, these will be pretty simple programs so you can see how things work. As we learn more about C, we'll write our own versions of FreeDOS programs like ECHO, PAUSE, CHOICE, TYPE, COPY, FIND, and MORE. And probably others like DATE, TIME, CLS, and DIR. By the end, we'll write a text-mode turn-based game.

Since C is also a popular programming language on Linux, almost everything that you learn in this series about Writing FreeDOS Programs in C will apply to Linux. You'll be able to write your own utilities and programs for Linux, too!

Welcome to the C programming video series!

How to follow along

Using FreeDOS

Throughout the video series, I will use FreeDOS to edit and run all the programs. Most of the time, I will use the FED editor. FED is a "folding editor" which means it can collapse blocks of code to make code shorter on screen. But more importantly, FED will apply colors to the source code that I'm editing, so you can more easily tell if l is a lowercase L or the number 1.

I will also use the IA-16 version of the GCC compiler. I could use any C compiler, like the OpenWatcom C compiler—which is a very nice compiler. But OpenWatcom is "noisy." It prints a lot of messages to the screen when I'm compiling, and that might make it harder for you to see if the compiler is complaining about something. The GCC compiler is much more "quiet," and only prints messages when there's a warning or error—if I've made a mistake in my program.

I might use OpenWatcom for part of the series, but most of the time I will use IA-16 GCC.

Note that there's another version of GCC included in the FreeDOS distribution. The DJGPP compiler is a 32-bit DOS version of GCC. That means programs compiled with DJGPP will only run on 32-bit CPUs. And while IA-16 GCC requires a 32-bit CPU to compile, the programs it generates will run on any 16-bit CPU. So if you're running a '286 or even a PC-XT, the programs compiled by IA-16 GCC should run fine.

To use IA-16 GCC, you need to set the DJGPP environment variable to point to the DJGPP.ENV file. You'll also want to make sure the GCC compiler is in your PATH variable. To do all that in a standard FreeDOS 1.3 RC2 installation, you can type these commands:

SET DJGPP=C:\DEVEL\DJGPP\DJGPP.ENV
PATH %PATH%;C:\DEVEL\I16GNU\BIN

You can find FED and IA-16 GCC in the FreeDOS distribution. IA-16 GCC is in the FreeDOS 1.3RC2 distribution. FED is in both FreeDOS 1.2 and FreeDOS 1.3RC2.

Using Linux

If you run Linux, you can easily follow along. Every major Linux distribution should come with a gcc package. That's the GNU C compiler (although "GCC" really stands for "GNU Compiler Collection"). You can use any editor to write your programs; use your favorite!

Using Windows

You can also follow along if you run Windows. You'll need a C compiler to work with. The Cygwin collection should do the job here.

However, I don't run Windows, so I won't be able to answer any questions about how to get Cygwin working. Sorry.

Resources and links

You can find lots of information on the Web already about C programming. Here are a few links to additional resources:

OpenWatcom Documentation
Additional documentation and references about C. Most of what we'll cover in this series will be standard C (except for conio, which is not part of the Standard C Library). See the OpenWatcom C Language Reference (clr.pdf) and the OpenWatcom C Library Reference (clib.pdf)
Learn C
An online "teach yourself C" tutorial.
C Tutorial - Tutorials Point
An online "teach yourself C" website.
The GNU C programming tutorial
An online "teach yourself C" tutorial. Originally published 1987, but after it went out of print, the authors released the manuscript.
Programming in C: Unix system calls and subroutines using C
An online "teach yourself C" tutorial, with lots of information about C programming on Unix.
Steve Summit’s home page
Has more information about C programming. Steve maintains the Usenet comp.lang.c Frequently Asked Questions list. Steve also used to teach C programming classes, and has shared the notes online.
Programming in C
Lots of mostly historical information about C programming.
Dennis M. Ritchie’s home page
Dennis M. Ritchie (dmr) created the C programming language while at the Computing Sciences Research Center of Bell Labs. Dennis passed away in 2011. This is an archive of his home page.
The C Programming Language, 2nd Edition
By Brian W. Kernighan and Dennis M. Ritchie. The original book about the C programming language. The book may be a tough way to teach yourself C if you're a first-time programmer, but it's the authoritative source about C and makes for a handy reference. [Amazon.com]