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.
The simplest program.
Open vim or your text editor of choice (Notepad for you Windows buffs). Type in the following:
Code:
#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:
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...