![]() |
C-programming for newbees! |
|
|
All c-systems generally contains of three parts:
*The environment
*The language
*Standard directorys
C-programs passes through six phases to become executed:
*Edit
*PreProcess
*Compilate
*Link
*Load
*Execute
Edit:
In the first phase you are going to write a program by using Edit in
dos or Notepad in win, the
only thing you have to remember is to write in 100% pure text.
You can not use any strange formats like: .doc .pdf
.wps.........
When you have written the program you should save it on a disk in C-format,
like:
CrackPatcher.c the only thing that is important is that the filename
ends with a .c
It could be a good idea to use a compleate IDE = Integrated Developed
Environment.
I use Borland Turbo C++ and C-builder3 Pro and i really recomend them!
PreProcessor:
When the program-code is written, it's time to compilate
the textfile. The compiler translates the c-program into machine-code (objectcode).
A preprocessor program is automaticly runned in a c-system before the
translation phase starts.
The c-preprocessing obey's certain commands called "Preprocessing
instructions" with indicates that some kind of manipulation are to be made
on the program before compilation. This manipulation can be: including
of other files to the file thats being compilated or it can be changing
of specialsymbols into programtext, or what ever!!
Compiler:
After PreProcessing the code is translated into machine-code.
Link:
You'll need a linker to link your code with external directorys.
A linker links the object code with the code for the missing function
to produce an executable image (without missing pieces).
Loadning:
Before the program can be executed it has to be placed in memory, this
is done by the
loader.
The loader takes the executable image from the disk and transform it
into memory and
finally the computer executes the program under control by the CPU.
Our first C-Program
We are going to code a program that types "Learn to program with TRES2000"
on
Your screen.
Here is the code:
-------------->8--------------------------->8--------------------------->8---------------------
/* C -exercise one */
#include <stdio.h>
main ()
{
printf("Learn to program with TRES2000\n");
}
---------------->8------------------------->8---------------------------->8---------------------
Line.1
The first line starts with: /* and end with */
this idicates that the line is a comment.
Comments are ignored by the compiler, the comment only explain the
programs purpose.
Line.2
The next line is: main( )
Main is a part of all c-programs, the ( ) after main indicates
that main is a program building block called function.
A c-program contains one or more functions and main has to be one.
All c-programs executes at the main function.
C-program starts to run at the first line in main and ends after the
last.
Between this the program can have jumped around to a lot of places
in and without
the main-function even to another main-function, which could be an
other program!
Line.3
The left brace { has to start the body of all c-programs.
The { in c is like
the <body> in html.
A { signals that somthing is a function and what is about to happen when it's called.
After the first { the story starts about whats happening in the
function and it ends with
the right brace }
programblock which is going to be placed together in the program and
are to be peformed
in the order it is, are to be within two braces so that the compiler
knows that it
hangs together.
So remember: A left brace to start a function and a right
brace to end the function!
Line.4
printf("Learn to program with TRES2000\n");
printf instructs the computer to perform an action, and what
action is that in this case?
Yes, it instructs the computer to type: Learn to program with TRES2000
on your screen!
The line to be typed on your screen is marked by quotation marks!
The the string that will be typed on your screen is called: character
string!
The entire line.4 is called: statement, the semicolon is called
statement terminater and works as
a dot (.)!
So we can say to make it easy: When you terminate a line when you'r
writing an essay or a mail,
you use a dot (.) but to terminate a line in C you are going
to use a semicolon instead;
Note: The \n is not typed out on your screen!
The
backslash ( \ ) means escape character and idicates that
printf is going to do
something
out of the ordinary.
Backslash
is used to get away from the standard sense.
It signals
that the next character that comes is a specialsign!
The backslash
combined with n makes an escape sequence that in this case (\n)
means
newline!!!
The printf-function is one of many functions in the ANSIC lib.