answersLogoWhite

0

Back in the days of MSDOS, before Windows, programs were run not in a graphical shell but in a text-mode command-line environment. The name of the program was typed in, and then the user would press ENTER to run the program.

Borrowing from Unix and CP/M systems, programs were given the option of having parameters sent to them - a list separated by spaces after the filename and a space, but before ENTER was pressed. This gave users the opportunity to tell the program how to run.

Windows still uses this system for passing information to a program when it runs the program. The parameters are passed in the same way, but every programming language has its own method of reading them.

Under C, you'll have likely noticed that sometimes you start a program with the following:

int main(int argc, char **argv)

{

...

}

"argc" and "argv" are used by your program to get these parameters. "argc" contains the number of parameters, and "argv" contains the parameter list.

Because the name of your program is always supplied as the first parameter, "argc" will always be at least 1, and "argv[0]" will contain the filename of your program.

"argv" is a list of character arrays - a list of null-terminated strings. The following program will demonstrate how to access the parameters supplied to your program:

#include

int main(int argc, char **argv)

{

int count;

for (count=0; count

printf("Param %d: %s\n", count, argv[count]);

return 0;

}

If you compile this and then run it at the command line, it will display on each line the list of parameters you feed it. For instance, passing the string this is a "test that I've" written will display:

Param 0: (the full path of your program, including directory and filename)

Param 1: this

Param 2: is

Param 3: a

Param 4: test that I've

Param 5: written

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What is the length command line argument in character?

Use the function strlen(string);


Command line argument?

Command line argument is a value that is passed to a program whenever the program is executed. It is used to avoid hard coding.


How you can got the first character of an argument in command line argument in java?

in your code u always write public static void main(String args[]) { //here array args will hold the command line arguments. Indexing from zero for //first argument //with substring(args[0],1) u can get 1st char of first argument. }


What variable will capture the content of the argument passed to a script at the command line?

If you read your book, you will find the answer!


How do you get the number of argument from command line?

It is very difficult task.but I will manage it by deep thinking on on the issue.


How do you end your command line?

Use "exit" command.


What variable will capture the contents of the second argument passed to a script at the command line?

If you read your book, you will find the answer!


Which variable will capture the contents of the second argument passed to a script at the command line?

$2Straight from the instructor. kinda simple eh?


What command in Windows RE can you use to rebuild the BCD file?

Use the command line: Bootrec/rebuildBCD


What reflects an accurate argument in favor of a command economy?

Which statement reflects an accurate argument in favor of a command economy


How do you use auto complete in the command line?

Tab button will auto complete a command


What is the way to use the run command line to open a command prompt?

run cmd.exe