5

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?

1

2 Answers 2

5
  1. Compile and link the project
  2. Open a command window
  3. Change directory to where the executable is created
  4. Run the executable
Sign up to request clarification or add additional context in comments.

2 Comments

@RandyHoward Yeah, I know! ;)
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.
1

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

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"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.