Jump to content

The history and basic's of C

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
nicckk

nicckk

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 629 posts
Hello all, this is a tutorial I wrote for my friend who wanted to get into C. I made a video for him to use however I cannot link it(Under 10 posts). The tutorial I wrote contains the basic history of C, and what C can do. Also included in it is the overused Hello World example. When your done reading let me know what you think, because I wish to keep writing tutorials.
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)


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Excellent tutorial! However, I did notice a couple of issues:
1) your program won't compile, you used Printf() instead of printf().
2) you used "witch" instead of "which" a lot.

Your history of C would make a great wiki entry.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
nicckk

nicckk

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 629 posts
Thanks WingedPanther for your insight. Like I mentioned I just wrote this in Word and I just read it in the video. I will now go by and edit it.

#4
Donovan

Donovan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 798 posts
Yes I think we should include this into a codecall Wiki page.
Posted Image
+Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

#5
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Very nice. +rep.

#6
TALucas

TALucas

    Learning Programmer

  • Members
  • PipPipPip
  • 91 posts
I like the 7 steps. Good stuff...so many times we think our job is done once we get a clean compile.
Your thoughts are the architects of your destiny.
[SIGPIC][/SIGPIC]

#7
nicckk

nicckk

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 629 posts
1.1 Multiple functions in C *Note, This tutorial follows where 1.0 left off*
Video-http://www.youtube.com/watch?v=oz2wAj1dfe4&feature=channel_page

In the last tutorial I asked the readers to create a program that would produce an output of “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.” If you wrote your code appropriately it should have looked like

#include <stdio.h>
main()
{
	printf(“For he’s a jolly good fellow\n”);
	printf(“For he’s a jolly good fellow\n”);
	printf(“For he’s a jolly good fellow\n”);
	printf(“Which nobody can deny\n”);
}

Now we will get started with the main purpose of the tutorial. In C you always start the program with the main() function. The textbook definition of a function is the basic module of a C program. The main() function can be identified as a function with the (). As you may recall the printf() command is a function as well, and the parenthesis are there also. Now I will begin coding, to show you what multiple functions means.

 #include <stdio.h>
main()
{
	printf(“Hello!\n”);
	two();
	printf(“Great!\n”);
}
two()
{
	printf(“The meeting time has changed\n”);
}

Now I will explain what is happening in the code. In the main() function there is two printf() commands with a start for another function in the middle. The main function ends with the }. Then the second function named two() begins with a printf() function in it. If you did everything correctly you should get a result of

Hello!
The meeting time has changed
Great!.

Thanks for you time.

Edited by nicckk, 25 December 2008 - 10:02 AM.


#8
Egz0N

Egz0N

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,034 posts
Nice Tutorial .. +rep :)

#9
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
Nice.
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz