G
Guru Programmer
Guest
Hey, this will be a guide on learning C in English
What I mean by this if any of you have tried to learn C before and do not know what they are talking about, and you
really want to learn it in ways that you can understand, this will be a great way to learn it.
C is a very good first language and once you learn C, it will make learning C++ 10 times easier.
So if you are thinking of starting C++ first, it is going to be a lot harder for you.
Note:This I am not writing this guide all at one time, I will be writing chapter by chapter.
Table of Contents:
Chapter 1: Getting the Required Tools
Chapter 2: Your First Program
Chapter 3: Coming Soon
( More Chapters, But Have not Written them Yet. )
Chapter 1: Getting the Required Tools
In order to program in C, you need a compiler.
What is a compiler?
When you write code, and try and run it, it will not work because the computer will not undertsand what you wrote.
A compiler basically converts the code you wrote into something that can be read and executed by your computer.
( Hence .exe files )
Compilers:
Microsoft Visual C++ 2005 Express Edition ( We will only use the compiler from this program )
Link: http://www.softpedia.com/get/Programming/Other-Programming-Files/Microsoft-Visual-C-Toolkit.shtml
To open compiler, Start>All Programs>Visual C++ 2005 Express Edition>Visual Studio Tools>Visual Studio 2005 Command Prompt
You are probably or maybe wondering, wait I am learning C not C++? So why am I using a C++ compiler?
Answer: Does not matter, it will Compile C perfectly.
Dev C++
Link: http://www.bloodshed.net/devcpp.html
To use the compiler for this, you will actually have to open the program
How do you compile a piece of code?
Open up your Visual C++ compiler, and you will notice it is a command-line interface.
Put your code into a notepad, save it with the extension .c in a desired location.
Go to that location using cd C:\Example
Then type cl program.c
A bunch of code will pop up.
See if there are any errors, if not your good to go
the compiler would have made a .exe file in the same directory as your program.c
To run the program, just type program without any extensions and you will see the output.
To use the Dev C++ compiler, you have to open the program and it is at the top. ( Figure it out ).
So once you have one of these compilers, you can move on to Chapter 2.
Chapter 2: Your First Program
If you have ever read a programming tutorial, it probably started with the Hello World program.
They do this because it is probably the most simple program you can write with any language and
it can explain alot.
Here it is in C:
What I mean by this if any of you have tried to learn C before and do not know what they are talking about, and you
really want to learn it in ways that you can understand, this will be a great way to learn it.
C is a very good first language and once you learn C, it will make learning C++ 10 times easier.
So if you are thinking of starting C++ first, it is going to be a lot harder for you.
Note:This I am not writing this guide all at one time, I will be writing chapter by chapter.
Table of Contents:
Chapter 1: Getting the Required Tools
Chapter 2: Your First Program
Chapter 3: Coming Soon
( More Chapters, But Have not Written them Yet. )
Chapter 1: Getting the Required Tools
In order to program in C, you need a compiler.
What is a compiler?
When you write code, and try and run it, it will not work because the computer will not undertsand what you wrote.
A compiler basically converts the code you wrote into something that can be read and executed by your computer.
( Hence .exe files )
Compilers:
Microsoft Visual C++ 2005 Express Edition ( We will only use the compiler from this program )
Link: http://www.softpedia.com/get/Programming/Other-Programming-Files/Microsoft-Visual-C-Toolkit.shtml
To open compiler, Start>All Programs>Visual C++ 2005 Express Edition>Visual Studio Tools>Visual Studio 2005 Command Prompt
You are probably or maybe wondering, wait I am learning C not C++? So why am I using a C++ compiler?
Answer: Does not matter, it will Compile C perfectly.
Dev C++
Link: http://www.bloodshed.net/devcpp.html
To use the compiler for this, you will actually have to open the program
How do you compile a piece of code?
Open up your Visual C++ compiler, and you will notice it is a command-line interface.
Put your code into a notepad, save it with the extension .c in a desired location.
Go to that location using cd C:\Example
Then type cl program.c
A bunch of code will pop up.
See if there are any errors, if not your good to go
the compiler would have made a .exe file in the same directory as your program.c
To run the program, just type program without any extensions and you will see the output.
To use the Dev C++ compiler, you have to open the program and it is at the top. ( Figure it out ).
So once you have one of these compilers, you can move on to Chapter 2.
Chapter 2: Your First Program
If you have ever read a programming tutorial, it probably started with the Hello World program.
They do this because it is probably the most simple program you can write with any language and
it can explain alot.
Here it is in C:
Code:
#include <stdio.h>
main()
{
printf("hello, world\n");
}
[code]
Do not understand any of this? Well I will explain this line by line.
[code]#include <stdio.h>[code]
Basically this means you are including a file to the Hello World program that has a set
of functions or commands in it.
<stdio.h> is the file we are including that holds many functions and commands such as printf
For right now just believe that printf is a command or function that is stored in the file <stdio.h>
and we are using it by including <stdio.h>
If we did not include <stdio.h> the printf function would be useless because it would not exist.
As you can see, to include a file, you use #include <filename.h>
You would include the file at the beginning of your code.
[code]main()[code]
main is a function, but not just any function, it is the function that every C program requires.
It is basically saying that this is the start of the program.
Without it, your program would not run.
So you would always start with the main() function.
What do the () mean?
If we were to have any arguments in our main function, we would put them between the ().
Do not worry about that now as you will learn about arguments later.
So always remember to have the main() function or command
[code]{[code]
This is a beginning bracket.
At the bottom you will see the end bracket }
Between { and } is where all your code in the main function have to go.
Whenever you put a {, there always has to be a } or else there would be no end.
[code]printf("hello, world\n");[code]
printf is a function that is stored in <stdio.h> along with other functions
printf is different from the main function because it does have arguments between the ()
The " and " specify that hello, world is a string. Remember, you specify a string with " and ".
What does the printf function actually do?
The printf function displays the string hello, world on your screen.
Simple as that, BUT WAIT, what is the \n thingy at the end of hello, world.
The \n is telling the printf function that after you print hello, world, start a new line.
So the output would look like this:
hello, world
( Newline ) Does not actually show the ( Newline ) , it basically just puts your cursor on the next line.
What happened if you put a space between world and \n
Output:
hello, world
( Still a newline but instead you told it to space once on the blank line.
So your cursor would be one space ahead on the newline.
If you had two spaces between world and \n, your cursor would be a space ahead on the newline.
Pretty simple :)
Just remember not to mix up \n and /n. It is \n and NOT /n.
Do not forget to close the argument with the ).
What is the ; after the )?
This ; says that this is the end of the argument, or a statement.
So whenever you are writing a statement, you must end it with ;.
So as you can see I got into a lot of detail with very little code.
But I hope you understand everything in the hello world program and you
should be able to write it yourself.
The best way to learn programming is not just by reading, try practicing what you read.
Make your own example program.
Try using a printf function that says:
Hi I am reading this tutorial
and I like it!
( If you need help just post :) )
Chapter 3: Coming Soon
















