Link:YouTube - Everything you need to know about C
________________________________________________________________
This tutorial focuses on the language C. I will be showing you the common Hello world example. However before we will go over some key points of the C language, including history and features. So here we go
Dennis Ritchie of Bell labs created C in 1972. Dennis and Ken Thompson both worked on developing Unix. C did not just pop out of Ritchies mind, the C language is based of Thompson’s B language. Certain languages can perform certain tasks. For example BASIC was developed to resemble English so student could have an easier time learning it. C overall offers shortcuts that can reduce your workload.
C has features that computer science theory and practice find desirable. C encourages to break down code into functions, however we will talk about that later in the tutorial. Also C is an efficient language. It is designed to be concise. There is a lot more about the history and what C can do, but that will be a later tutorial. Now let’s get started.
Whenever programming you should start with a clean example of what you want done. For this example I want the code we write to print the statement “Hello World!”. The next stop is writing and compiling code. After you have a feel how your program works and feels its time to start debugging. Your program can run, but there are probably still some bugs that you could find and fix, before the official launch of your million dollar program. Debugging as a definition is finding and fixing problems in your code.
As I learned C I followed 7 basic steps; however I fell that one main point is missing. Here are the seven steps
1. Define the program objectives
2. Design the Program
3. Write the code
4. Compile
5. Run the program
6. Test and debug the program
7. Maintain and modify the program
I fell that there is a step missing between 6 and 7. What’s missing is distributing your code, witch we shall get into later.
Now we need to talk about supplies. For a program to exist it needs to be written. You can use any text editor, however I recommend one with syntax highlighting for the language you wish to write in. You also need a compiler, because a computer cannot understand written phrases, code needs to be compiled into machine code. Currently I use Devc++ 5.0 beta 9.2.
If features a text editor with syntax highlighting and a built in compiler. Make sure you download the version with minGW/gcc
Now you may be wondering what is syntax? I have mentioned this word before. Basically syntax is the grammatical arrangement of words in sentences, basically it has to do with grammatical concepts. As you can have a syntax error in English such as cheetahs run fast do, not only do you sound like Yoda but your sentence has syntax errors. Code can also have syntax errors, and they must be cleared of before you can compile.
Now finally let’s start writing the program. I talked about earlier what objective I want the program to complete. C is a top to down language you start high up defining broad code, and work your way down to specific code.
First we need to add the include. The include pre-process instructions. Following the include is the main function, witch then is followed by other functions. Braces mark the beginning and end of each function. Note that parentheses cannot do this. It has to be braces(They look like this, {}). Now I will introduce you to the printf() function. It prints a message. The f is there to remind you it is a function. The printf function is similar to BASIC’s PRINT command.
So lets start coding, as you may recall we need to start the program with an include. I will be using stdio.h or standard input output header. So let’s add it. You must add the pound sign before the statement include so if you were to type it out it would look like this
#include <stdio.h>Now we add the main function and brackets. Now we have
#include <stdio.h>
main()
{
}
Now I will add the printf function within the brackets.
#include <stdio.h>
main()
{
printf(“Hello World!\n”);
}
So you may be wondering what the backslash n means. In C it means new line. You have to remember add a semicolon after every line of code in C or else you will receive a syntax error. Now I will show you how to run the program, or at least how I do it. Compile your code to the desktop. Now move it to a folder that you know were it is located. For example I use my temp folder,c:\temp. Open command prompt and type in cd (location here). Cd is the command for dropdown. Now type in the files name and it should run.
Now try writing a program yourself. Try to code a program that can print
For he’s a jolly good fellow
For he’s a jolly good fellow
For he’s a jolly good fellow
Which nobody can deny
Remember you can hit enter to start a new line and type out the printf function with parentheses and quotation mark and it will show up on a new line. That’s it for now. My next tutorial will be on multiple functions in C.
Edit: Fixed some vocabulary, and added a section I forgot, and added a link to the video.
Edited by nicckk, 22 December 2008 - 05:02 PM.
add code tags (the # button)


Sign In
Create Account


Back to top











