Sunday, March 30, 2008

argc and argv

So today's brief blog is about the argc and argv in that appear besides the main function when dealing with c++ console applications. Basically argc is the number of arguments that the program gets when its open, and *argv[] is an array that contains the arguments. The first argument tends to be the direction in your hard drive of the program, and the next arguments may vary. For example you could open your program using the command prompt and write something after the dir of the program, and that will become the argument. Separate it by space and you will have more arguments. Now, what things can we do with this. I mean, we might like to use the command prompt, but the users usually don't so whats use for them?
One nice thing about it, its opening files. Try making a file and end it with anything you want after a dot like .test and create a program that uses the second value of argv to open and read from the file. Then open your file with the program. Guess what, the second value will be the direction to the file. So you will have your own custom file.

back to the code.

No comments: