Logo designed by CO2 - http://www.planetquake.com/CO2
Logo designed by CO2 - http://www.planetquake.com/CO2
Logo designed by CO2 - http://www.planetquake.com/CO2
Logo designed by CO2 - http://www.planetquake.com/CO2
   
Back to HomePage

Back to Tutorial menu

Credits

  • Puke
  • SumFuka
  • Saqquara

  •  

      What did I just do??

    /* hiworld.c Hello World program! */
    #include <stdio.h>

    main()
    {
    printf("Hello, world\nBye bye, world");
    }

    Now, this was the code you compiled in the previous tutorial. Lets show you what you were doing, and take it line by line.
    OK, the first line includes the code '/* Hiworld.c Hello World program */'. This is a comment line. Basically, when compiling, the compiler skips past all the text in between the '/*' and '*/'. The comments sole purpose is to help the programmer remember what the code meant, if he were to come back to it later, and to simply make the code easier to read for someone that didn't program it.
    In line 2, we have the first bit of actual "code". Essentially, all it does, is replace the '#include <stdio.h>' with the code found in the stdio.h file (in LCC's include directory), so all the functions, etc. (in this case, printf) can be called in your program.
    Next, on line 4 we have the declaration of the 'main' function.
    After that on the next line is the bracket '{', which indicates the beginning of the code, which makes up function 'main'.
    On line 6 we call the printf function. Technically, although printf is a one of the most popular functions, it is not part of the C language, so it must be declared before it can be called. This declaration occurs in stdio.h. Then, in the parentheses, is the parameter(in this case 'Hello, world\nBye bye, world') which is passed to the function, and then displayed on screen.
    You may have noticed the funny bit in the middle of the string. \n creates a line break, so Hello, world, and Bye bye world, will be on different lines. Then the semicolon terminates the statement.
    After that comes the closing bracket '}', which indicates the end of the code, making up function 'main'.

    Exercise

    Find 2 ways of printing some text on 3 seperate lines.
    Example:

    /* Example! */
    #include <stdio.h>
    
    void greet(void)
    {
       printf("Hi world of Quake!\n");
    }
    
    void QuakeChat(void)
    {
       printf("Quake 2 rocks the world!\n");
    }
    
    void farewell(void)
    {
       printf("Cya l8er Quake dudes!\n");
    }
    
    
    
    int main()
    {
       greet();
       QuakeChat();
       farewell();
    }

    Now, you try and think of another 2 ways to do the same!

    Tutorial by Puke


    Back To Tutorial 1 Forward To Tutorial 3
                   
    
    

     

    Logo designed by CO2 - http://www.planetquake.com/CO2

    This site, and all content and graphics displayed on it,
    are ©opyrighted to the Quake DeveLS team. All rights received.
    Got a suggestion? Comment? Question? Hate mail? Send it to us!
    Oh yeah, this site is best viewed in 16 Bit or higher, with the resolution on 800*600.
    Thanks to Planet Quake for there great help and support with hosting.
    Best viewed with Netscape 4 or IE 3