tags:

views:

1746

answers:

5

I want to run a C program in DOS prompt. Is it possible?

+6  A: 

If You mean MS-DOS mode in winXP for example:

start->run

type: cmd

goto your program path

cd C:\Your\program\path

type

yourprogram.exe

thats it.

bua
He said a C program, not a .EXE. Given that this site is for developers, I think we should assume that the OP is clever enough to understand how to run a binary executable file.
Michael Dillon
@Michael Dillon: But a C program *is* an executable, otherwise it is just source code and not a program at all. I don't think the OPs intent is as clear as you suggest, and that is not the interpretation (no pun intended) I'd have put on it.
Clifford
@Michael Dillon C being a compiled language, i dont know what you expect. The TCC option is valid, yet a smoke bomb IMO. If this question was "how to run a c program in linux", wouldnt it be ok to do $yourprogram ?
Tom
You have to be very much a beginner to not know that C is normally compiled into binary executables which the operating system runs for you. Yes, its possible that the OP just doesn't understand command prompts at all, but I think the TCC/CINT answer is the most interesting given that many seasoned programmers are not aware of C interpreters. It was a C interpreter that led us to Javascript, after all.
Michael Dillon
A: 

Open the prompt, and just type in the location of the exe, e.g. c:\MyProg\Prog.exe

YoungPony
A: 

You can run a compiled c program (i.e. one that has been compiled to an .exe file) at the DOS prompt (by simply running the .exe as other answers suggest). You cannot directly run a .c file at the DOS prompt.

GOR
+4  A: 

Yes, it is possible. You can install TCC which allows you to put

#!/usr/local/bin/tcc -run

as the first line of your source code. This is a compiler that will compile and run directly from source code.

Another option is to use CINT which is a C interpreter. This will allow you to run C programs from the CMD prompt in Windows, which is what most people still call the "DOS" prompt.

Michael Dillon
Seems like the least likely interpretation of Sumeshsankar's intent. Most likely IMO he is a novice who has only ever executed his code from within an IDE and does not realise what is happening under the hood.
Clifford
I agree that your interpretation is the most likely one, but an answer that explains how everything works under the hood is not terribly useful to others. C interpreters are something that people might have a use for. After all, CMM (aka CENVI) was one of the grandaddies of Javascript (the other main grandad being Sun's SELF).
Michael Dillon
A: 

First you need to download Dev Cpp compiler. After downloading install it. I assume you are installed C:\ drive. Now create file called filename.bat extension. write text as follows... set path=C:\Dev-Cpp\bin;C:\Dev-Cpp\libexec\gcc\mingw32\3.4.2

now open cmd....

go to save location of filename.bat and run it.

filename.bat

after setting path go where is saved file... for example c:\save\

Now compile your C file using gcc compiler...

gcc filename.c OR filename.cpp

and execute .exe file...

a.exe

Have fun...

Govind