Basics of C Programming
There are a few basic elements of C Programming. This article will cover these things.
#include
First, all programs have to have an #include function. The #include function adds libraries to the program. Libraries are files that kind of expand C and add some commands and functions to it. For example, you cannot do GetInteger(); without...I think the genlib.h library.
Anyway, it should look like this:
#include <stdio.h> //stdio.h is a library for printing things according to my experience
it can also look like...
#include "genlib.h" //genlib.h is another library for the basics of C Programming
The include function should always be at the very top of the program.
...Also, these // are comments to take some notes while you do your programming. To make comments, do this:
//aljflsfljsdsl --the lsadkjfsl is the comment. Whatever is at the right of the // will be ignored by the compiler.
You can also do /* and */ for comments. It goes like this, sort of like brackets.
/*
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
*/
Warning! If you put a /*, but no */, the program is going to treat every thing below the /* as comments. So think of the /* */ like parenthesis or brackets in math. If you miss one out, you get a syntax error.
#include
First, all programs have to have an #include function. The #include function adds libraries to the program. Libraries are files that kind of expand C and add some commands and functions to it. For example, you cannot do GetInteger(); without...I think the genlib.h library.
Anyway, it should look like this:
#include <stdio.h> //stdio.h is a library for printing things according to my experience
it can also look like...
#include "genlib.h" //genlib.h is another library for the basics of C Programming
The include function should always be at the very top of the program.
...Also, these // are comments to take some notes while you do your programming. To make comments, do this:
//aljflsfljsdsl --the lsadkjfsl is the comment. Whatever is at the right of the // will be ignored by the compiler.
You can also do /* and */ for comments. It goes like this, sort of like brackets.
/*
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
*/
Warning! If you put a /*, but no */, the program is going to treat every thing below the /* as comments. So think of the /* */ like parenthesis or brackets in math. If you miss one out, you get a syntax error.
main()
A program will also need a main task. It looks like this:
main()
After that would be brackets {}. A regular program would look like this:
main()
{
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
}
The main() initiates the main program, which is whatever is in the brackets. The BLAHBLAHBLAH are just some commands the program does. I'm just lazy to type :P
main()
After that would be brackets {}. A regular program would look like this:
main()
{
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
BLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAHBLAH
}
The main() initiates the main program, which is whatever is in the brackets. The BLAHBLAHBLAH are just some commands the program does. I'm just lazy to type :P