
-----------------------------------
Dan
Thu Mar 20, 2003 7:12 pm

[Tutorial]An Intro To C
-----------------------------------
An Intro To C

The C language is very different than Turing in many ways, so you may have trouble adjusting to it if you have done a lot of work in Turing but practice makes perfect ;)

Ok, one of the most common assumptions is that C and C++ are the same language. They may be very similar but the coding will very from each one. You can wire C code in almost anything but you will need a c compiler to run it. You can usually find a free C compiler on the net, or if you are using Linux it will already be installed in your OS.

C is mostly used for console apps, which means they will be mostly text and run in a dos window. This may make many people think that C is a useless language, but truthfully it has a lot of applications still and is a very good introduction to c++.

We will start with what almost all c codes contain in them. C programs will have a function called main which is where the main part of your program will go. Also, before declaring this function you will have to tell the complier that you are using the C language and what libraries and header files to include.

This is what the start of a basic c program may look like:


#include  // this tells the computer to use 
//the C library almost every c program has this in it

int main () //declaration of the main function,
//this is needed in almost every c program
{
printf("Hello world!!!!"); // put the words "hello world" on the screen

return 0;
}


How it works

Ok, first off, one of the main things you will need to know in C is that after most statements you need to put a ;. Also, another important thing to remember in C is to put the include statement to call the C library. All the code for the main function have to be within the { and }. The return 0 code tells the main function that it has run its course and to exit out of it and end the program.


The code for displaying text on the screen goes as follows:

printf("put text here"); 

This code will display the text in between the "'s on the line that was last specified. To move down one line put a \n in the "'s when you want to go to the next line.

And as all ways don't forget the ;  at the end of the printf statement.


Well that's the very simple b of c, If I get time I will post more info on c and c++. If you want to learn more there are a lot of good web sites out there and I would recommend the book "C Primer Plus".

EDIT: i chaged the code to have int main() insted of void main() to be more corect and to increas proiblaity

-----------------------------------
jamez
Sat Apr 26, 2003 7:56 pm


-----------------------------------
Also instead of 
printf("Hello World.")

You can usecout 