 |
| C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

January 12th, 2007, 09:17 PM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
take arguments when running program in console
Hi,
I am a newbie to C++. I'm almost sure that there is the possibility to take parameters when running program in console.
Ex.:
program.exe /a etc ...
How can I get those parameters and values in program?
Thanks in advance!
|

January 14th, 2007, 07:33 AM
|
|
Authorized User
|
|
Join Date: Oct 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi,
i think you should locate the file you saved.....
im not sure about your problem what do you want to intend for...but i guess your problem if im not mistaken is you want to run your program in console..
what if you download the windows application of c++ like (dev-c++)....
______________________________________
.::If you quit you loss, If you survive you win::.
.::JHANNY::.
|

January 14th, 2007, 06:20 PM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Nice reply, but it's not what I want.
I give you an example: i've created a program in c++ ( :) so I know about Dev-C++, Visual C++) and now I want to run the program from phph through system() or exec().
exec("program.exe /arguments_here")
Question based on the above example: how can I get the /arguments_here list?
|

January 16th, 2007, 08:20 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2006
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
|
|
if I am understanding your question correctly than you want it to where in the command prompt you can type :
program.exe /a 2 2
where program.exe uses a as a parameter to add the two numbers
this may not be what your program does but I'm using this as an example. If this is what you would like to do then you are in luck because it is absolutely EASY!!!!
~ Geo
~ Don't take life too seriously, you'll never get out alive!
|

January 16th, 2007, 08:27 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This is exactly what I intend to do. But I can't figure out. Maybe using some parameters for function main()?
|

January 16th, 2007, 08:33 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2006
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Exactly!!!!
In order to do this you must create parameters for the main function
EX:
int main(int argc, char *argv[]) {
char x = *argv[1];
int a, b;
a = atoi(argv[2]);
b = atoi(argv[3]);
}
now ignore the atoi function if you don't know what it is. (Parsing function)
What the above shows is parameters that are used for the example I posted above
this can apply to anything.
The argv[] applies to what you type after your program in the console window
so if its the first parameter it will be argv[1]
now this may be slightly confusing if you don't understand pointers so if you have any more questions about it just ask.
~ Geo
~ Don't take life too seriously, you'll never get out alive!
|

January 16th, 2007, 08:58 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This is exactly what I wanted to do. Thanks!
P.S. I agree with you about the last line in the post (quote :) )
|

January 16th, 2007, 09:01 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2006
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
|
|
No problem, is it working?
If you have any issues or additional questions just ask.
And this is my favorite quote because if you don't take time to take a break you'll end up missing your chance
~ Geo
~ Don't take life too seriously, you'll never get out alive!
|

January 16th, 2007, 09:17 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I did not test it. I'm at work right now and I have something else to do. I got the ideea. When I first see your post some things were unclear in my head: what is argc. I hit search on google and I found.
|
|
 |