Computing.Net > Forums > Programming > Command line arguments in VisualC++

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Command line arguments in VisualC++

Reply to Message Icon

Name: Aboroba
Date: March 27, 2003 at 15:37:11 Pacific
OS: XP
CPU/Ram: 258
Comment:

Does anyone know how to use the command line arguments with Visual C++?
I have used it in Linux like this:
void main (int argc, char* argv[])
and it worked fine, I wonder if it is possible in windows/Visual C++!

Your response is really appreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: egkenny
Date: March 27, 2003 at 17:14:30 Pacific
Reply:

Visual C++ works the same way:

void main(int argc, char* argv[])

argc contains the number arguments
argv[] is an array of pointers to character strings

argc equals number of arguments plus 1
argv has pointers to argc plus one strings:

With no command line arguments (n=0)
argc equals 1
argv has pointers to 2 strings:
argv[0] contains the name of executable file
argv[1] contains null

With n command line arguments
argc equals n + 1
argv has pointers to n + 2 strings:
argv[0] contains the name of executable file
argv[1] to argv[n] contains the arguments
argv[n+1] contains null


0

Response Number 2
Name: Madhavan
Date: March 28, 2003 at 05:06:28 Pacific
Reply:

Yes, as egkenny said, its the same in VC++.


0

Response Number 3
Name: Aboroba
Date: March 31, 2003 at 13:14:27 Pacific
Reply:

Thank you guys for responding.

Well, I tried it but it seem like I am missing something:
For me, when I run it in Linux environment, I use the g++ compiler and create the object output file ( by using the -o operator) and then I type this output file along with my input files in the command line.

In VC++, to run the program I just click the "!" button so I did not know where to list my input files.
Any further help please?


0

Response Number 4
Name: egkenny
Date: March 31, 2003 at 19:38:47 Pacific
Reply:

Normally you do the same thing in Windows by opening a DOS command window.

If you want to test it in Visual C++ do this:
Select: Settings in Project menu
Select: Debug tab
Program Arguments: enter command line arguments here


0

Response Number 5
Name: Aboroba
Date: April 2, 2003 at 18:11:24 Pacific
Reply:

Thank you egkenny, it did work..
Now I've one further problem, that is how to use a wild card in the command line arguments..
the program i am working on requires entering a punch of different files each time i run it,
for example if i have these files in the directory a1.txt a2.txt a3.txt b1.txt b2.txt b3.txt c1.txt c2.txt c3.txt,
to enter the files start with a I use the * wildcard so a*.txt will make the program (in the linux environment) recognizes 3 files, similarly I could enter *2.txt or *.txt.
When I did this in VC++ it did not work, it read a*.txt as 1 file and could not open it " because it actuall doesnot exist", I also tried % and _ as wildcards but neither has worked..
Any idea how to do this in VC++..
It is really painful to enter the file names one at a time especially when you know there might be more than 70 files per run.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Command line arguments in VisualC++

command line argument in C ?? www.computing.net/answers/programming/command-line-argument-in-c-/4446.html

C++ Command-Line Arguments www.computing.net/answers/programming/c-commandline-arguments/4864.html

Testing command line arguments www.computing.net/answers/programming/testing-command-line-arguments/19061.html