C Compiler

Discussion in 'Programming' started by cancer10, Jul 12, 2008.

  1. #1
    cancer10, Jul 12, 2008 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    shallowink, Jul 12, 2008 IP
  3. cancer10

    cancer10 Guest

    Messages:
    364
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can I have screenshots for the links you provided? The site does not show any screenshots there :(
     
    cancer10, Jul 12, 2008 IP
  4. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #4
    Bloodshed has a screenshot here:
    http://www.bloodshed.net/images/devcpp5_scr.jpg

    Seriously doubt you will see screenshots for GCC or LCC-Win32 since IIRC those are command line. If you are looking for IDEs, that's a totally different requirement.
     
    shallowink, Jul 12, 2008 IP
  5. cancer10

    cancer10 Guest

    Messages:
    364
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ok I downloaded Bloodsheed Dev C++

    I am trying to run this code

    #include <stdio.h>
    
    int main()
    {
        printf("\n");
        printf("Hello World");
        printf("\n");
    }
    
    Code (markup):

    It compiles ok, and a DOS screen comes for a few milliseconds and disappears.

    Why is this hapenning? And How/Where do I see the output?

    Sorry, I am new to C.


    Thanx
     
    cancer10, Jul 12, 2008 IP
  6. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #6
    Its doing exactly what its supposed to do. And that is creating a dos application that prints hello world. If you want to actually see the output you will have to go to a DOS Prompt. Change directory to whereever you compiled the file and type its filename to see the output.

    Here's the steps:
    open cmd from Start>Run
    cd dev-cpp
    project2.exe

    That assumes you have bloodshed installed on the C: drive. If you select windows application from the Project list it will show a bare windows app.
     
    shallowink, Jul 12, 2008 IP
  7. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #7
    Program runs and screen disappears becuase you have to hold the program for a while for certain action, because it quits when function main has completed.

    #include <stdio.h>
    #include <conio.h>
    
    int main()
    {
        printf("\n");
        printf("Hello World");
        printf("\n");
        [B]getch();[/B]
    }
    
    Code (markup):

    Most recomended : mingw-gcc that comes alongwith DEV C++ IDE. I am using it since 5 years. I even do windows programming using this IDE.

    I hope it helps.

    regards
     
    Vooler, Jul 12, 2008 IP
  8. hamik112

    hamik112 Peon

    Messages:
    334
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    CodeBlock is a great compiler, the program executed fine, it finishes so fast you can't see it. You need to have a loop so it keeps going, or ask for input so, you can see the output.
     
    hamik112, Jul 13, 2008 IP
  9. cancer10

    cancer10 Guest

    Messages:
    364
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hi

    That getch(); helped.

    Can some one please explain me the difference between:

    1) int main()
    2) void main()
    3) main()


    Thanx
     
    cancer10, Jul 13, 2008 IP
  10. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #10
    int main() - is right, and program should have a main function returing integeger back to system.
    void main() - is not right but few compilers change it bacn to int main() when compiling.
    main() - only using main() without return type was once accepted and compilers used to accept such functions, but still made it int miain() when compiled.

    So, solution is, use int main() nothing else, but when writing windows programs (non-console), it is different story, you need to use int WindMain(). Few compilers like mingw-gcc do accomodate int main() in windows programs too, but it is not recomended.

    CodeBlocks is not a compiler, but an IDE that integrates mingw-gcc with it already, just like DEV C++. Please do not feel my words rude or offensive, it is my duty to correct nw programmers, so that they are not mislead in future.

    regards
     
    Vooler, Jul 13, 2008 IP
  11. hamik112

    hamik112 Peon

    Messages:
    334
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Lol, no offense taken. I'm not a new programmer, just a careless mistake.:D
    I think I can provide a simpler explanation. int main() basically is the main function that runs when you run the program, everything goes into that function. The Int is just Integer that is returned to see if the program was successful. If it was successful you return 0.
     
    hamik112, Jul 13, 2008 IP
    Vooler likes this.
  12. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #12
    :) Very nice explanation of 'main' function.. rep added.

    regards
     
    Vooler, Jul 13, 2008 IP