![]() ![]() ![]() Printf("The argument supplied is %s\n", argv) argv - would contain base address of the string "PR2.C"įollowing is a simple example which checks if there is any argument supplied from the command line and take action accordingly − #include.argv - would contain base address of the string "PR1.C".argv - would contain base address of the string "filecopy".In our sample program, if at the command prompt we give, filecopy PR1.C PR2.C The argument argc is set to the number of strings given on the command line. More precisely, the strings at the command line are stored in memory and address of the first string is stored in argv, address of the second string is stored in argv and so on. When the program is executed, the strings on the command line are passed to main(). Out of these, argv is an array of pointers to strings and argc is an int whose value is equal to the number of strings to which argv points. The function main() can have two arguments, traditionally named as argc and argv. The full declaration of main looks like this: int main (int argc, char *argv) The arguments that we pass on to main() at the command prompt are called command line arguments.
0 Comments
Leave a Reply. |