Site hosted by Angelfire.com: Build your free website today!
C Programming

About this website

The purpose of this website is to teach the C programming language. I'm assuming that you have no previous programming experience so I'll try to explain things as best as possible :-)


What you will need

In order to create programs, you need a compiler. A compiler is a program that translates your code (in this case C) into a binary format that the computer understands. If you are in Windows, you might want to try Bloodshed Ddev-C++. It is a great free compiler from the folks at Bloodshed Software. Other alternatives are Microsoft Visual C++ which costs money and how you get a copy of that is your business :p. I personally don't like MS Visual C++ because it confuses me. If you are a Linux user then you could use the almighty GNU C Compiler :)

First Program

Now are are going to create our first program. This is a very primitive program that will output text to the screen. Type the following code into your compiler or whatever editor you wish to use:

#include<stdio.h>

main()
{

          printf("Dear diary:\n");
          printf("NIKKIE AND I HAD SEX LAST NIGHT AND NOW WE ARE IN LOVE!\n");
          getchar();

}

If you compile and run that, a black box should appear with the program's output. Lets analyze this program :)

The first line of our program is #include<stdio.h>. This just tells the compiler to include the Standard Iinput Output library, which contains most of C's basic functions and saves us the work of typing them all out ourselves :) Every C program needs this library.

Next we have the main function. In C (any many other programming languages) programs can be split up into blocks called functions. A function is simply part of a program that contains code. Every C program has a main function, and the code inside the main function is what gets executed first even if there are 100 functions above it. We call the main function by typing main() and a curly bracket. Functions also end with a curly bracket.

Inside the main function, we used printf (print function). This function outputs text to the screen, remember to put the text in quotation marks. Notice at the end of printf we typed \n for new line. Adding \n makes any text after it appear on the next line, much like the text from the second printf did in this program.

And finally, I added the getchar() function at the end of the program. Programs end when they reach the end of their code, so I added getchar which waits for the user to press enter before continuing the program.