home

Tutorial index

C Tutorial: Lesson 1: Intro

            Programming should not be regarded as hard or easy. It is very easy to start programming (at least in C, which we will study), and it is fairly easy to continue, as long as you have the right teacher. The problem is that teachers are different, and often they speak to an audience other than the one you are in.

This is why I chose to write these tutorials. The tutorials on C are aimed at those who want a relatively fast course into programming, oriented mostly toward game programming as they will cover what you need to continue with the GDI, XNA and any other tutorials I might make in the future. I advise you to focus more on the C++ tutorials for practice as C++ replaces some C functions with far more practical ones.

But before we start you will need a compiler. C works on pretty much any computer as most popular operating systems are built on C and C++, however you will have to heed the OS version of compilers (that means that DevC++ for Windows will nor run on Unix, and vice versa). I will suggest you use Dev-C++ by Bloodshed, it is one of the most popular free compilers around, though many prefer others. GCC is also a well known compiler which might come with your Ubuntu OS, but it is a command line compiler which I find impractical and highly annoying. In any case, find whichever one is more suitable for you, go to it’s page, find the download tab, select the right version and download it. While installing look out for a few things:
-Advertisement oriented checkboxes for setting your default browser, start page or setting up any toolbars. You absolutely do now want anything messing around with your computer in that way.
-Options for specific file types. Chances are the installation will ask you if you want it to associate specific file types with the compiler, make sure you have .c and .cpp files checked.
-Installation directory. Chances are your projects will be somewhere in the installation folder. Visual Studio places them in it’s own folder in MyDocuments, but each compiler has it’s own way of working. With GCC and other such compilers you do not have to worry about that as you will have it create the executables where your manually created source files are, or in the case of DevC++ and other compilers with an IDE (Integrated Development Environment, which generally means a graphical user interface (UI)) you will do everything from within the program.


Now on how to compile and work with various compilers, so I do not have to waste any more text on compiler specific details in the future. For GCC you will open a command prompt window in the directory with your source file and type: gcc <mysourcecode.c> -o <programName>. This tells it, in this order, to start GCC compiler, use a file named mysourcecode.c, specify the output (-o) to be called <programName>. DevC++ and Visual Studio have multiple working areas, the largest one is where you write your code, the lower one is where any errors during compilation are displayed, and other ones can be set up so you can see other files in the project or for any other functionality that is provided. There should be a “build” tab somewhere on top, after File, Tools, Edit and so on, there you will find a compile command, or possibly compile and run. In Visual Studio you can hit F5 and then select Yes when prompted to build the solution, or first build it and then execute directly, Ctrl+Shift+B followed by F5.


I assume you can find the File -> new project option, so make one, name it whatever you want, select it to be a C or C++ project, console application if anyone asks, and start coding! For GCC you will have to make a .txt file and rename it to .c when it’s ready for compilation, or directly a .c file and open it with a text editor (such as Notepad, Notepad++, Pico, Nano, Gedit and so on).