PDA

View Full Version : Lets All Learn C!!!!!!


Anman
2004-09-15, 11:09 PM
I wrote this for a group of linux wannabe programmers. Ya'll might have use for it too. Since you all look like wannabes.
If it makes no sense, just tell me what you don't get, and I'll try explaining it. Or just PM me or something.

Firstly,

Why learn C?
C allows a great deal of control over the computer system it is running on, as well as being capable of running on any OS, from Windows to Linux, and on nearly any system, PDA to supercomputer.

But what is C?
C is a programming language, much like java or basic. It is basically a set of instructions that the computer has to follow, allowing you to make it perform tasks. C originated several decades ago, and has come to be used by the vast majority of programmers due to its level of control, and it's efficient management of resources.
C is an example of a compiled language, meaning that after your program is written in a simple text editor, it must be turned into an executable file (.sh or .exe) by another program called a C Compiler. You can get a free c compiler from the DJGPP project. (http://www.delorie.com/djgpp/)

The simplest program.
Open vim or your text editor of choice (Notepad for you Windows buffs). Type in the following:


#include <stdio.h>

int main()
{
printf("Hello World!\n");
return 0;
}


Now to save your file. For a C Compiler to correctly compile a plain text program, it must be in *.c format. For this example we are going to save the file as test.c. Now, after making sure that your extension is correct, let's have a look at the parameters used in the program.

#include <stdio.h>: This is the standard I/O library used in computing. It allows text to be displayed on screen, and receive input from the keyboard. C has quite a few libraries available, making various processes even simpler for you to use in your programs.

int main(): This is a function. main is the name of the function, while int is declaring that a new function is about to start. All C programs must have a function named main, as it's the first function to be run when your program is started.

printf: This command tells the program to write to the standard output, which in this case is the screen. The section in the quotes is the format string, which shows how the data will be formatted when displayed. The \n signifies a carriage return, meaning that the program will start a new line.

return 0: Sends an error code of 0 back to the program. 0 represents no error.

Now to compile our program. Browse to the directory that you saved test.c into using command prompt. To compile, type the following:


gcc test.c -o test.exe


Now it's just a matter of running your compiled exe!

If all goes well when you run your program it should display the text 'Hello World!' before exiting.

More to come...

Sovereign
2004-09-15, 11:40 PM
Wrong forum. Moved.

WetWired
2004-09-16, 07:05 AM
Why not C++? C lets you get away with too much. Default function prototypes? Default variable types? Set a non-const pointer to the value of a pointer to const?

Sovereign
2004-09-16, 08:01 AM
We can't have that!

What the fuck did you just say?

Tyrannicide
2004-09-16, 01:29 PM
Plus MJ already made a C Tutorial thread. He alaborated a lot more me thinks.

Demosthenes
2004-09-16, 01:40 PM
Plus MJ already made a C Tutorial thread. He alaborated a lot more me thinks.

Once I have a bit of time I need to finish that up.

Mantralord
2004-09-16, 02:28 PM
#include <stdio.h>

class Anman {

public:
Anman() { ShutsUp(true); };
~Anman() {};
void WhatIsAnmanDoing();

private:
boolean ShutsUp;

};

void Anman::WhatIsAnmanDoing(){
if(ShutsUp) printf("He finally shut up!\n");
}

int main(){
Amnan idiot;
idiot.WhatIsAnmanDoing();
return 0;
}

Anman
2004-09-17, 06:31 AM
DAMIT! THIS WAS SUPPOSE TO SPAM !!!! I HATE YOU ALL!!! *runs knife through each rib rivet*

Demosthenes
2004-09-17, 10:16 PM
Anman, what distro are you running?

Demosthenes
2004-09-17, 10:32 PM
#include <stdio.h>: This is the standard I/O library used in computing. It allows text to be displayed on screen, and receive input from the keyboard. C has quite a few libraries available, making various processes even simpler for you to use in your programs.

Probably be a good idea to define what a library is.

int main(): while int is declaring that a new function is about to start.

??

All C programs must have a function named main, as it's the first function to be run when your program is started.

Not necessarily.