How to Compile C Program in Command Prompt?

How to Compile C Program in Command Prompt?

You will need a C compiler For compiling "C" program via cmd for that refer tho this thread - How to install mingw?

Step -1
Checking Mingw is properly installed or not for that
  • Open "cmd" by simply pressing "windows key + R" it will open Run then type "cmd" there then hit "Ok"
  • It will open command prompt (cmd) then type
gcc --version

  • It will show the installed Mingw version
  • If it throws error 
 'gcc' is not recognized as internal or external command
          then u need to install Mingw again by following the above guide properly

 Step-2
  • Create a c program and store it in your system. I have written a simple "Hello World" program and stored it in the Desktop. We would be using following code.


  • Remember save the file with extension ".c"
  • For my case the name of the file is "1.c"
  • Now open cmd (Windows key + R & search cmd )
  • In cmd type 
cd "location of the c program file"

  • For my case the file is in "Desktop"

  • Now in cmd type 
gcc "Name_of_the_file.c " -o output_file_name
gcc 1.c  -o hello 

  • Now the program is compiled sucessfully  & we can run the program
  • Type
    hello.exe
     

         Congratulations, you've compiled & run a C program by using the command line(cmd)!

0 Comments