THREAD: C Programming #1 Hello World
  1. 06-27-2017, 03:46 PM
    Zone1337's Avatar
    Zone1337
    Keeper
    Zone1337's Avatar
    Zone1337
    Keeper
    10
    Posts
    10
    Reputation
    Nov 2016
    NextGenUpdate
    Sup boi this is my first C programming Tut. C is a very good language to learn and if you want to learn C++ I recommend learning C first. These tuts will not cover the history or anything like that it will only cover the code so before we begin here is a good resource that is good to use for references do not READ it work it what i mean by that is write out all the examples and try to do the exercises*C.*

    C Programming Language, 2nd Edition*

    So lets begin so in this tut i will go over a simple program which is the Hello world program to make this we use the code below.

    int main(){
    * *printf("Hello World);
    * *getchar();
    }

    The above code will print the text Hello World to the console and then will wait till the user has pressed ENTER or clicked the x to close the program.

    So the first line that will be executed is int main(){} this is a function we use functions to store all of our code in unless you want code to be global. Everything between the {} are called statements. Statements should usually end with ; but sometimes do not. If you have have some previous programming knowledge in C# you might of heard of a method or in vb.net you might of heard of sub routines they are just functions with different names don't ask why I have no idea why.

    The next line that will be executed is printf("Hello World"); this will print hello world to the console as printf is used to print characters to the console.

    The last line that will be executed is getchar(); without it the program will open and close really fast so we use getchar(); so it will wait until we press ENTER or click the x to close the program.

    so that's my first tut done i know its really short but there is no point in learning a lot of stuff and then having to learn it all the next day because you cant remember it.*

    Exercises:
    make your own program using printf and getchar make the output be you name and age and make sure they are commented // <- that's a comment.*

    If you want more just say Smile
  2. 03-15-2018, 09:50 AM
    MrRa1n's Avatar
    MrRa1n
    League Champion
    MrRa1n's Avatar
    MrRa1n
    League Champion
    1,743
    Posts
    15,333
    Reputation
    Jun 2010
    NextGenUpdate
    The main method you have declared is of type int but does not return a value. Try using void instead or add return 0; to the end of the method. Also, instead of using getchar(), just give main a couple of parameters to read command line arguments. Lastly, you are calling the printf() function. This is included in the C standard library, so add #include <stdio> to the very start of your code.

    An example below:



    #include <stdio.h>

    int main(int argc, char **argv)
    {
    printf("Hello, World!\n");

    return 0;
    }

    Last edited by MrRa1n ; 03-15-2018 at 09:59 AM.

  3. The Following User Thanked MrRa1n For This Useful Post:


  4. 09-15-2018, 05:40 AM
    3
    Posts
    10
    Reputation
    Sep 2018
    NextGenUpdate
    Originally Posted by Zone1337 View Post


    int main(){
    * *printf("Hello World);
    * *getchar();
    }



    You can also add a do while loop if you want to make the program infinitely run until the user exits...


    int main(){
    * *do {
    * *printf("Hello World);
    * *getchar();
    * *} while (1)
    * *return 0;
    }
  5. 12-03-2018, 01:00 PM
    Algebra's Avatar
    Algebra
    [move]mov eax, 69[/move]
    Algebra's Avatar
    Algebra
    [move]mov eax, 69[/move]
    297
    Posts
    8,520
    Reputation
    Dec 2014
    NextGenUpdate
    Originally Posted by Zone1337 View Post
    Sup boi this is my first C programming Tut. C is a very good language to learn and if you want to learn C++ I recommend learning C first. These tuts will not cover the history or anything like that it will only cover the code so before we begin here is a good resource that is good to use for references do not READ it work it what i mean by that is write out all the examples and try to do the exercises*C.*

    C Programming Language, 2nd Edition*

    So lets begin so in this tut i will go over a simple program which is the Hello world program to make this we use the code below.

    int main(){
    * *printf("Hello World);
    * *getchar();
    }

    The above code will print the text Hello World to the console and then will wait till the user has pressed ENTER or clicked the x to close the program.

    So the first line that will be executed is int main(){} this is a function we use functions to store all of our code in unless you want code to be global. Everything between the {} are called statements. Statements should usually end with ; but sometimes do not. If you have have some previous programming knowledge in C# you might of heard of a method or in vb.net you might of heard of sub routines they are just functions with different names don't ask why I have no idea why.

    The next line that will be executed is printf("Hello World"); this will print hello world to the console as printf is used to print characters to the console.

    The last line that will be executed is getchar(); without it the program will open and close really fast so we use getchar(); so it will wait until we press ENTER or click the x to close the program.

    so that's my first tut done i know its really short but there is no point in learning a lot of stuff and then having to learn it all the next day because you cant remember it.*

    Exercises:
    make your own program using printf and getchar make the output be you name and age and make sure they are commented // <- that's a comment.*

    If you want more just say Smile


    Bisual Vasics