I am stuck in this whole concept of using the command line to pass arguments(or parameters, dont know which is the correct name) to main().
I have input and ouptut files that need to be supplied to my program on the command line, which i will access using int argc, char *argv[].
I use Quincy as my IDE, so what do i need to tpye on the command prompt to pass my input and output files to my program.(i know the text files names go somewhere but the rest?)
Notice how the second argument has quotes because it has a space.
If you type the above, argv[1] would contain "C:\\Users\\Admin\\Desktop\\file1.txt" and argv[2] would contain "C:\\Users\\Admin\\Desktop\\A Folder\\file2.txt". argv[0] would contain the full path to the executable. Backslashes need to be escaped in a string so that they don't invoke some undesirable escape sequence. You only need to put single backslashes in the command line.
So i go to start, command prompt, there I have C:\Users\Admin> now i just add to that
program.exe C:\Users\Admin\Desktop\file1.txt "C:\Users\Admin\Desktop\A Folder\file2.txt"
i did this and i got a message saying " 'program.exe' is not recognized as an internal or external command, operable program or batch file"
I knew it was a place holder, anyways, i think i finally got it. I did what you said and received a message saying, something like:
Argument1: (the place of my program, it ends with program.exe), Argument2: (tha place of my output file, it ends with output.txt) Argument3: (the place of my input file, it ends with input.txt)
So it basically sends 3 arguments to the program even though i only wanted to send the input and output file??
so every time i work on the program and test to see if it is working or not, do i have to go back to
the command line and type the same thing all over again??
When i pass the 2 arguments to my program ( 3 if you count the location of the program) through the command line, the program runs right there in the command prompt. It shows me the 3 arguments (argv[0] argv[1] argv[2])
However, when i go back to the IDE (Quincy) and try to run the program it displays only 1 argument - the location of the program
The command line interpreter has a history function. If you press up or down, you can navigate the history to re-enter some past command.
Most if not all IDEs have a setting that let you specify what arguments to pass to the program when you debug. It's usually with other debug options, such as the working directory and environment variables.