Learn C ( Guide )

Discussion in 'Programming General' started by Guru Programmer, Aug 14, 2008.

Thread Status:
Not open for further replies.
Learn C ( Guide )
  1. Unread #1 - Aug 14, 2008 at 8:57 PM
  2. Guru Programmer
    Referrals:
    0

    Guru Programmer Guest

    Learn C ( Guide )

    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:

    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
     
  3. Unread #2 - Aug 15, 2008 at 4:03 AM
  4. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    Learn C ( Guide )

    A great way to learn it is not another millionth helloworld tutorial. Also, you call yourself a Guru, when you must earn that title.

    Wrong, wrong and WRONG. I hope you realize that anything written in C is directly backwards-compatible with a C++ compiler. I also hope you realize that C++ is just building on top of C, hence there is hardly any difference other than the features which it has added (which in turn can make it quite a lot EASIER). I learned C++ first, hence I already knew most of how to program C.

    When you try to run code, the compiler compiles your code in to assembly, which is a direct set of computer instructions. You don't seem very knowledgeable on the matter, and you didn't elaborate much at all.

    You obviously have no idea what the difference is between a compiler and an IDE. They're _very_ different. An IDE (Integrated Development Environment) is a tool to assist in the writing of code. The compiler compiles the code. Most IDEs come with a compiler (a completely different program) to compile the code to make it easier for the user to develop. You do not require an IDE such as Dev-C++ or MSVC to compile code. I commonly use the GCC compiler and command-line alone.

    Because the hello-world program is a general introduction does not mean it is the best thing to do. Most languages have a hello-world tutorial, but they are mostly useless. Hello-world hardly explains anything about programming.

     
  5. Unread #3 - Aug 15, 2008 at 8:31 AM
  6. Govind
    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    Learn C ( Guide )

    pwned!

    I agree with Swan, your guide needs serious rework.
     
  7. Unread #4 - Sep 18, 2008 at 5:44 PM
  8. Code zombie
    Referrals:
    0

    Code zombie Guest

    Learn C ( Guide )

    ...It least the dude was trying to help, he deserves some credit
     
  9. Unread #5 - Sep 19, 2008 at 1:58 AM
  10. Swan
    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner

    Swan When They Cry...
    Retired Global Moderator

    Learn C ( Guide )

    When you've seen as many helloworld tutorials like these ...

    Mate, face it. These people just rewrite the same tutorial and expect some sort of credit. They convince themselves (or not) that they are trying to help the community, but they expect attention from it, and when they don't get it, they leave.. That's how it works, unfortunately.
     
  11. Unread #6 - Sep 20, 2008 at 6:47 AM
  12. htaed
    Joined:
    Dec 19, 2005
    Posts:
    336
    Referrals:
    0
    Sythe Gold:
    0

    htaed Forum Addict
    Banned

    Learn C ( Guide )

    I agree that it must of taken him some time, but swan did pwn his face :D
     
  13. Unread #7 - Sep 20, 2008 at 7:47 PM
  14. Govind
    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    Learn C ( Guide )

    In any case, he's banned now. Useless tutorial = LOCKED
     
< An Idea of mine | Anyone know how to make a username leecher? >

Users viewing this thread
1 guest
Thread Status:
Not open for further replies.


 
 
Adblock breaks this site