How to pass Command Line Arguments in Turbo C++

The following are the steps to execute a program with Command Line Argument inside Turbo C/C++ Compiler :

1. Open Turbo C++

Open Turbo C++. If you don't have, you can download Turbo C++ from here.

2. Write a program

Following is a simple example which checks if there is any argument supplied from the command line and take action accordingly −

#include <stdio.h>
#include <conio.h>

void main( int argc, char *argv[] )  {  
   if( argc == 2 ) 
      printf("The argument supplied is %s\n", argv[1]);
   else if( argc > 2 ) 
      printf("Too many arguments supplied.\n");
      printf("One argument expected.\n");

Click here to open this program in Turbo C++

3. Compile and Run your program

When the above code is compiled and executed by Turbo C++, it produces the following result

One argument expected.

4. Open DOS Shell

Now open Turbo C++ File Menu (You can use shortcut Alt+F) and select DOS Shell.

5. Change directory

Now you need to change the current directory of DOS Shell to "SOURCES" from "BIN", for this you need to user cd command.

  • First use cd.. for coming back to Turbo C++ main directory

  • Now use cd SOURCE to access the SOURCE directory

      cd SOURCE

6. Execute Program with Command Line Arguments

ARGS.EXE testing  

Here ARGS.EXE is the executable of your program ARGS.C and testing is a command line argument. When you'll hit the enter, it produces the following result

The argument supplied is testing  


Read Community Guidelines
You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.