Introduction to C (Lesson One)

By Ice Dragon
Please realize that these lessons were designed to give you a feel for the workings of C. You will never master C by reading electronic documentation, you only have three good ways to fully learn C:
1)Find a mentor IN REAL LIFE. This is usually not an option since it is hard to find somone you know who is willing to patiently teach you everything.
2)This is the best method if you are too young to go to college: Buy 2-3 beginner-level C books (usually $20 a piece). Once you've mastered those books, go on to harder ones.
3)If you're 17-18 and are going to college soon, you can start with method 2, then enroll in a college that teaches C programming and takes courses in it. This is the absolute best method (and the most costly), since you will be reading books that an experienced programmer feels is good, and plus you'll have some advice from a real programmer.

 Now onto the lesson: As you may know, C is an extremely popular computer programming language. This probably because:

I'm not sure what the difference between C and C++ is, because I have only studied a little in each. But since it seems C++ is very rarely seen in exploit code, I will introduce you to C. All you need is a C compiler. If you're running Linux or you have a shell account with compiler access, you're in luck. All you have to type is 'compile'. But many of us (including me) are still running Windows 95. In this case, you can download the shareware version of my favorite C/C++ compiler: Borland Turbo C++ Lite. Unfortunately, since Borland changed it's name to INPRISE, I haven't been able to find any free downloads, although I know it is shareware. Fortunately, the zipped setup package was only 1.2 MB so I uploaded it into my GeoCities account. You can download it here It should be noted that C++ compilers support C 100%. Before you can get into exploit programming, you're going to have to learn the basics. If you don't, you won't understand many of the advanced topics. Now if you downloaded Turbo C++, you are provided with a space to write your programs when you run tc.exe. But if you're using Linux, you'll have to settle for a plain-text editor. You can access it by typing: ed, ex, edit, emacs, or vi. If none of these work, you'll have to check your Linux manual or consult the admin of your shell account provider. Ok, now you're in a text editor. Let's talk about the 'C preprocessor'. The preprocessor is used to handle commands before the main part of your program starts. It is usually used to access library files. Library files tell your program what different commands do. The 'standard' C library file is called 'stdio.h' (STanDard Input/Output). So the first line of your preprocessor should be
#include <stdio.h>
The '#' sign tells the compiler that the command is part of the preprocessor. Next, every program needs a 'function main' (for those of you familiar with BASIC, a function is very similar to a subroutine). Functions are identified by () after the function's name. So the next line would be
main()
. To signal the start of function main, we need to put a
{
Now we get into to the main part of this program where we start issuing commands. One command to display something on-screen is 'printf'.
printf("Hello!");
Printf (and nearly every other command) is actually a function. This function is contained in stdio.h. With functions, you put 'parameters', or information used with the command, inside the (). In this case, the parameters would be what you want to display. Also, since Hello! is not a variable, you must put it in quotes to tell the compiler that Hello! is the exact phrase you want to display. When calling functions, you must always put a ';' at the end. To end function main(), you must put a
}
at the end. So your whole program should look like this:
#include <stdio.h>
main()
{
printf("Hello!");
}
This ends Lesson 1. In Lesson 2, I will go into different kinds of variables, input, operators, and if-then statements. I know I haven't given you much to work with this time, but this lesson was required just to introduce you.
Bibliography: C Primer Plus
 
Back To Index