2

I want to create a small C program and I would like to use the Windows command prompt to compile and run it. Can anyone suggest to me how to install a C compiler that works with the command prompt and the way to use it? How do I install the compiler, compile the code and run the program?

Thiago Silveira
  • 5,033
  • 4
  • 26
  • 29
123Ex
  • 21
  • 1
  • 2

3 Answers3

3

There's several compilers available for Windows. Two popular ones are Microsoft Visual C++ and MinGW.

Using Visual C++, you can compile a program like so:

cl /Femyprog.exe myprog.c

Using MinGW, you can compile a program like so:

gcc -o myprog.exe myprog.c
icktoofay
  • 126,289
  • 21
  • 250
  • 231
3

Download Visual Studio Express 2010 C++. From the File menu, choose New, then Project. Under Project Types, expand the tree view to Visual C++ -> General, then choose the template for Empty Project. Give it a name and a location. Click OK. Type in some C code, then Build and Run it.

It's a fairly simple tool to use, so I'd recommend you just go ahead and try it out.

Brian Kelly
  • 19,067
  • 4
  • 53
  • 55
  • 1
    And here is a command line compile walk through: http://msdn.microsoft.com/en-us/library/ms235639.aspx – Robert Groves Apr 30 '11 at 04:30
  • thanxxx for the reply,Sounds like good one,But I want to do this in command prompt – 123Ex Apr 30 '11 at 04:43
  • When you run the program from Visual Studio as I described, it will be launched automatically within a command prompt window which will also close when your program exits. If you wish you could also run `cmd` and then `cd` to your project directory and run the `.exe` yourself that way. – Brian Kelly Apr 30 '11 at 04:54
1

Most programmers don't use command prompts to compile very much any longer. We use IDE's instead, because they're a hell-of-a-lot more convenient. Having said that there's no reason why you can't use the command prompt to "manually" execute the compiler which underlies, say, Microsoft Visual Studio.

So... If I where you I'd start by downloading Visual Studio 2010 C++ Express Edition from Uncle Bills Funny Farm. Note that C++ IDE (and compiler, or course) supports the old ANSI-C language as well as C++... in fact C++ is a "superset" of ANSI-C.

Your other options are a bit limited on Windows. I believe that GCC: GNU's C++ Compiler works on Windows... but it's "got a few issues" which nobody is any particular hurry to fix, simply because by far the majority of the GNU boys are running Linux, and they sort-of look down on Windows as "an interesting experiment [which failed]".

Cheers. Keith.

corlettk
  • 13,288
  • 7
  • 38
  • 52
  • 1
    Thanxxx ,First I want to tell.I'm new to the C and don't know how to start,I would like to do it in first command prompt and then move to IDE,I appreciate your valuable suggestions,I will move to IDE when I know the basic things in C – 123Ex Apr 30 '11 at 04:46
  • That's IS a good approach. Doing these things manually initially gives you an understanding of what your IDE is doing for you "under the hood"... and when the IDE fails, you've got a hope of understanding the problem well enough to fix it, or atleast work-around it manually. – corlettk Apr 30 '11 at 05:11