Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    8
    Rep Power
    0

    Steps to write a "hello world" program.


    hello everyone,

    I really need your help. I am a java progammer not a c programmer. I am currently trying very hard to understand what are the steps to get a simple program such as:

    #include
    int main()
    { printf("hello world\n");
    return 0;
    }

    to run. From my knowledge of java, I know that I must have a JDE or JDK environment. then I must write program, compile it using dos "javac hello.java", then run it using dos "java hello".

    can someone kindly lead me through the process of achieving this goal through step by step instruction. Please don't refer me to another website (the more I read online the more confused I get). I know this has to be as simple as 1-2-3. so I kindly ask if some one would be patient in explaining this to me.

    thank you for your time.
  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    Step 1) Get a C/C++ compiler. There are free and others out there to be purchased. I use gcc and vc++.

    Step 2) Write a simple hello world program, lets call it hello.c.
    i.e.
    Code:
    #include <stdio.h>
    
    int main(void) {
        printf("Hello World\n");
    
        return (0);
    }
    Step 3) Compile the application
    gcc -o hello hello.c
    This line compiles the file into an executable called hello

    Step 4) If no errors occured, run the program
    hello
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    8
    Rep Power
    0
    hi onslaught, first thank you for your reply,

    when you said:Step 3) gcc -o hello hello.c
    Step 4) hello
    are those commands done in dos/command prompt?

    also whats a good free c/c++ compiler in your opinion?

    third, do compilers recognize c and c++ or do I need a seperate compilor for each?

    thank you.
  6. #4
  7. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    yes, those two steps are done from the command prompt.

    gcc is a good c/c++ compiler
    gcc is a compiler package that comes with compliers to compile c, c++, obj-c, java, and I think a few others.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2001
    Posts
    1,481
    Rep Power
    15
    Just so you know: C is a subset of C++, so if you have a C++ compiler, then you can compile C programs.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2000
    Posts
    763
    Rep Power
    0
    Didn't C++ come frome C? Wouldn't that make C++ a subset of C?
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    8
    Rep Power
    0
    thank you very much. If I have any more problems I will post here.
  14. #8
  15. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    no by definition if C++ were a subset of C then all elements of C++ would be found in C which they arent.
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    8
    Rep Power
    0
    frankly, I have never been so lost in my life.

    I am here http://mirrors.rcn.net/pub/sourceware/gcc/
    chaos rules my mind. any hints how to download gcc.

    also, I have managed to download the dev-c++ 4.9.8.0 package. would there be a problem in the future if I had downloaded gcc also. I am curious because I know in Java this would cause a hybrid JDK?
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    8
    Rep Power
    0
    I am also wondering what is the command for compiling and running using "Bloodshed Dev-C++" I have searched the entire help section and could not find? and how do you know thats the command to compile?
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    8
    Rep Power
    0
    for the above comment, I was refering to the command from 'command prompt/dos'
  22. #12
  23. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    To download gcc, you need to go to the release section and pick a version to download.
    Something like: http://mirrors.rcn.net/pub/sourcewar...eases/gcc-3.3/

    An easier method, but a larger download would be to download the cygwin environment, which gcc comes with. This environment emulates the environment of unix/linux which gcc is the compiler that comes with those operating systems.

    As far as compiling with Bloodshed, it should be basically the same, depending on what the compiler name is, the options are still typically the same.
    For visual C++ the compiler name is cl.exe
    So you could go cl -o hello hello.c

    I believe, but I could be wrong, that dev-c++'s compiler name is devcpp.exe

    As far as having multiple compilers, this shouldn't be a problem except in a case where you have your path set to both compilers and they are named the same thing. This would be a case where things would go wrong.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2000
    Posts
    763
    Rep Power
    0
    The Dev-C++ is an IDE which can use the gcc, ming or other compilers. I believe there is a package that you can download from them that contains the ming compiler.
  26. #14
  27. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    8
    Rep Power
    0
    hi guys.

    to anyone who has the same question. actually the dos command to compile from dev-c++ is:

    g++ c:\dir\filename.c -o c:\dir\filename.exe

    I have also downloaded the borland compiler. its commands from dos is:

    bcc32 c:\dir\filename.c .....etc.

    thanks to onslaught and all those who helped me out.
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Location
    Flint, MI
    Posts
    328
    Rep Power
    13
    hitman,

    If you're using Dev-C++, rather than stressing over the command line you might just want to hit the compile button on the IDE. It's also a menu option.
    Clay Dowling
    Lazarus Notes
    Articles and commentary on web development
    http://www.lazarusid.com/notes/
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo