How to execute a c program using bat file in windows OS.



How to execute a c program using bat file in windows OS.



Step 1 :

Install gcc compiler or any compiler


Step 2:

Create a file with extension XXX.bat using following code


REM - is command which mean comment (like in C as /* some comments about the code */)


REM set the compiler path to variable CC. Here SET is a command which put the compiler path in CC
SET CC="C:\TDM-GCC-64\bin\gcc.exe"


REM call compiler using CC between % symbol is syntax then “-o” command for creating object file then give the path of the object file with filename and extension then give the
REM  XX.c file which is needs to be compiled.
%cc% -o  E:\gopi\Official\C_learning\Hello_world.exe "E:\gopi\Official\C_learning\Hello_world.c"


REM Here executing the XXXX.exe will provide the out put.
E:\gopi\Official\C_learning\Hello_world.exe


Step 3:

Go to the XX.bat file path which is created in step 2 and “Shift” key + Right click then select “ Open command window here ” then type XXX.bat file name and click Enter.

Comments