devxlogo

Command Line Parameters

Command Line Parameters

Question:
I want to write a DOS program that takes command line parameters and uses them in the program.For example, if the program was comline.exe and you typed in the command line:

comline one two three

the program should display something like:

Parameter 1: one
Parameter 2: two
Parameter 3: three

Answer:
That’s an easy one. Try this:

void main(int argc, char *argv[]){   int i;   for (i = 0; i < argc; i++)      printf("Parameter %d: %s
", i, argv[i]);}

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist