What's New!

Chat with

How to Defend
Your Computer 

The Guides
to (mostly) 
Harmless Hacking

Happy Hacker 
Digests (old stuff) 

Hacker Links 


Meet the 
Happy Hacksters 

Help for 



It Sucks 
to Be Me!

How to Commit
Computer Crime (not)! 

What Is a 
Hacker, Anyhow? 

Have a 
Great Life! 

News from the 
Hacker War Front

(also see the GTMHH on How to Program in C)
By Meino Christian Cramer <root@solfire.ludwigsburg.netsurf.de>
    with a few additions by Carolyn Meinel.

Newbie Note:  This lesson requires that you have a Unix shell account.  To learn what a shell account is, see the GTMHHs on how to get a good shell account.  If you know what a shell account is but don't have one, you can find an Internet Service Provider that offers them from http://www.celestin.com/pocia -- or try http://shells.cmeinel.com, or get your own Unix shell by installing some sort of Unix on your home computer.  For details on how to do this, see the GTMHH on Linux.  The easiest forms of Unix to install on your home computer are Caldera (http://www.calderasystems.com), Red Hat (http://www.redhat.com), Slackware (http://www.slackware.com) or Debian (http://www.debian.com) Linux.

In this guide you will learn:
1.0 What Is "C" ?
2.0 What do we need to program in C?
3.0 The first program
4.0 C compiler vs. C compiler
4.1 If your compiler is a K&R or "old" compiler
4.2 If your compiler is an ANSI-compiler
5.0 Parts and pieces of a C program
6.0 Your Programming Environment
7.0 How to use libraries
7.1 Quick Review
8.0 Data Types
9.0 The anatomy of a procedure
10.0 A very special data type: pointers
11.0 Text, Strings, Arrays and more Pointers
12.0 Pointer Arithmetics
13.0 Structures
14.0 IO -- Input/Output
15.0 Additions and conclusion:
16.0 If it doesn't work...
17.0 Cc, Gcc And The Rest Of The World 

## 1.0 What Is "C" ?

    "C" is a programming language. "C" is THE programming language! :-) It is the language in which both the most powerful hacker exploits, most Unix type operating systems and very much of the programs, which you can get for free from internet sites, are written.

    The power of "C" is like the power of a fast car: Use it carefully and sensibly and you will be a winner. Use it without any knowledge and control and you will go off-road, next to a tree.

    More seriously: The design of "C" lets you make things not possible in other programming languages. "C" is the programming language for those of you, who want to gain control over the whole thing, to break into computers, or to keep the bad guys out of your computer. "C" gives YOU, the programmer, the full responsibolity, what will happen.

    OK, there are traps inside "C".  And you WILL fall over them. But, hey, we are learning from errors, we are hackers, so we want to learn, cause we are curious, therefore, there is no better way for us to learn than to make errors. The only error which should not be made is the error of avoiding errors... :-)

This tutorial will introduce the programming language C to you and it want to makes you a little bit curious. It is far beyond the scope of it to TEACH you C. If you want to learn C seriously, buy a good book about C. My favourite one is written by the inventors of C, Brian W. Kerningham and Dennis M. Ritchie and is called "The C Programming Language".

    All example programs given in this tutorial, are written for an ANSI-type of compiler. But in the following you will find tips, how to change the source codes easily, so that they will compile on K&R types of compilers without errors. You mainly have to change the beginning of the function definitions and their prototypes a little bit.

Happy learning, Happy Hacking!

Let's start the story to tell.....

### 2.0 What do we need to program in C?

First, let's see whether your account is prepared for you to program in C!

Log into your account and type: 


Or if this gives the result "command not found", try:


. This will call a program called "C compiler" (that's why the command is called "cc").   Note: if "gcc" works instead of "cc", then for the rest of this C porgramming guide substitute "gcc: everywhere you see "cc".

 If you have a C compiler you will get an error message (that's quite normal!) but at least you  don't get the message "command not found", whihc means you don't have a C compiler.  If that is the case, get an account with an installed C compiler.   For a list of Internet service providers around the world that you can use to search for one that offers a shell account with a C compiler,  see http://www.celestin.com/pocia.

Or, better: Install LINUX (it is not that hard! If you are able to install Windoze, you are able to install LINUX!), then install gcc, the GNU C compiler, available from http://www.gnu.org.

You have a C compiler installed at your account? Fine! But....what IS a C compiler?

    Do you remember ancient times, when hackers used hex-editors and cryptic tables of "foreign number codes" to write very very very fast and short programs? You don't?  OK, too bad you aren't old like us:) Anyhow, those programs were called "assembler" programs. "Assembler" is the native language of the central processing unit (CPU) of your computer. Because the
only thing which is important for assembly language is to be fast and readable by the CPU of your computer, it is made of a nothing more than a bunch of NUMBERS.

    But then people (not only hackers) wanted to write programs which were easy to for humans to understand. So they invented the "compiler languages". These languages were made from words (commands) instead of numbers.  Now humans could read those words, but CPUs couldn't.

    Wrong design?

    Not really, because some egg heads also invented programs called "compilers".  Each programming language need its own compiler.  The task of these compilers is to translate the words into assembly language. The input to a compiler is a text file consisting of a (more or less) logical sequence of words, the commands which the programmer has written. This text file is
called the "source code", because it is the "source" of the program.  The result of a run of a compiler is another file, called an "executable program".  An "executable program" is one which you can run just by typing in its name.  Have you ever tried to run those computer break-in programs you find in places like http://www.rootshell.com?  If you type in the name of a file that holds C source code, it just sits there and does nothing. You have to compile it before you can run the program.

"Programming" means to divide a task into smaller and pieces until these pieces can be expressed by a sequence of commands.

Click here for more --->

Carolyn's most
popular book,
in 4th edition now!
For advanced
hacker studies,
read Carolyn's
Google Groups
Subscribe to Happy Hacker
Visit this group


Return to the index of Guides to (mostly) Harmless Hacking!

 © 2013 Happy Hacker All rights reserved.