How to run a c program using command prompt on win 7 with codeblocks installed and if location of c file is different than default location?
2 Answers
- Compile and link the project
- Open a command window
- Change directory to where the executable is created
- Run the executable
2 Comments
Some programmer dude
@RandyHoward Yeah, I know! ;)
Shubham Saxena
first thank you for your help.I want to compile the c file from the command prompt itself.what is the command for compiling given i am in the directory containing the file. gcc filename.c did not work.
I'm not a windows guru, but that should be pretty easy. Just so that we are on the same page here: your "c file" is just a text file. Your codeblocks is just a fancy text-editor for that text file. When you click "compile" your codeblocks invokes a compiler - a program which translates the c instructions in the textfile, into binary. Now, run the following command to go to the main directory.
cd C:\
Than run
dir /s /b myfile.c
if you are looking for your uncompiled c file. If you are looking for the binary:
dir /s /b myfile.exe
To run your program :
C:\path_to_program\program.exe
2 Comments
Shubham Saxena
first thank you for your help.I want to compile the c file from the command prompt itself.what is the command for compiling given i am in the directory containing the file. gcc filename.c did not work.
GCC is a compiler, you probably don't have installed on your system. "Compilers" are just programs that translate code into native instructions. You can map the compilers location, so you don't have to type it through the windows environment variable. If you have visual studio installed, you can run a visual studio command prompt and type "cl" to compile your file. Your other option is to download a compiler, and type "PATH/TO/COMPILER/compiler.exe arguments"