Run c program using command prompt in window



Introduction :C Program can be run using Command Prompt .We can use MS-DOS to run c Program. Every window OS comes with inbuilt Command Prompt. So we are going to use this command prompt to run our c program.

Pre-requisite :

  1. Window’s Command Prompt
  2. Turbo C/C++ Compiler

Why we should run C Program using Command Prompt?

  1. We have Stored our C programs inside directories other than (C:/TC/bin) then we are unable to run c program.
  2. In order to run C Program we must copy C Program and paste it inside bin folder.
  3. This process is bit time consuming and complex.

Running C Program using Command Prompt :

  1. Create One Directory in D Drive (in my case my directory is “C Programs”)

  1. Now we must have Turbo C/C++ IDE installed in your system.( You may download it from here)
  2. After installing Turbo C/C++ IDE we have this directory Structure

  1. Now Right Click on My Computer Icon and Click on Properties

  1. Click on Environment Variable Button.

  1. Make entry of bin inside Path Variable.

  1. Make Entry of TC>bin inside Path Variable and Click on OK.
C:\TC\BIN
  1. Now Open Command Prompt by typing cmd inside “Run” Option.
  2. Go to Path Where you have Saved your C Programs.
Microsoft Windows [Version 6.1.2025]
Copyright (c) 2009 Microsoft Corporation.  All rights 
reserved.
C:\Users\Santoshi>D:
D:\>cd C Programs
D:\C Programs>
  1. Suppose we have Saved hello.c program inside “C Programs” folder. then type this command to Compile hello.c
D:\C Programs>tcc hello.c
Turbo C++ Version 3.00 Copyright (c) 1992 Borland 
hello.c:
Turbo Link  Version 5.0 Copyright (c) 1992 Borland 
        Available memory 4106832
  1. After typing “tcc command” we can compile C Program.
  2. Now its time to run C Program after Successful Compilation.Just Type Program name and Hit Enter you will get output on the console
D:\CPROGR~1>hello
Hello

Note :

Actually tcc.exe Command is located inside C:/TC/bin So we have make this entry inside path variable so that Command Prompt can find this command from that specified path.