Main Arguments
-
Hi guys, I am writing a simple program that the user would like to be able to run from the command prompt. I am wondering how I pass that infromation into the main of my program. For example, if you wish to run Windows explorer from the command line you pass the command "explorer". This will launch Windows explorer and default to showing C:\. However, you can also call explorer and have it open a specific directory "explorer C:\Test\MyTest". My question is this: Is the second part of that simply passed as the argument to main? For example if I wanted my program to specify a string, could I have my main function accept a const char *? I.E.
void main(const char *inputString)
? where inputString would be whatever it is that I have passed immediately after my *.exe name? so the total call would be something like: C:\> stringParser This Is My Test which would hopefully pass a pointer to "This is My Test" into my main argument. Thanks, Joe -
Hi guys, I am writing a simple program that the user would like to be able to run from the command prompt. I am wondering how I pass that infromation into the main of my program. For example, if you wish to run Windows explorer from the command line you pass the command "explorer". This will launch Windows explorer and default to showing C:\. However, you can also call explorer and have it open a specific directory "explorer C:\Test\MyTest". My question is this: Is the second part of that simply passed as the argument to main? For example if I wanted my program to specify a string, could I have my main function accept a const char *? I.E.
void main(const char *inputString)
? where inputString would be whatever it is that I have passed immediately after my *.exe name? so the total call would be something like: C:\> stringParser This Is My Test which would hopefully pass a pointer to "This is My Test" into my main argument. Thanks, JoeIn Visual C++, you can use the version of _tmain that has command line argument parameters: int _tmain(int argc, _TCHAR* argv[]) See main: Program Startup[^] Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
In Visual C++, you can use the version of _tmain that has command line argument parameters: int _tmain(int argc, _TCHAR* argv[]) See main: Program Startup[^] Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
Mark Salsbery wrote:
int _tmain(int argc, _TCHAR* argv[])
strange from microsoft that argv is not an array of
**const** TCHAR*
:|
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Mark Salsbery wrote:
int _tmain(int argc, _TCHAR* argv[])
strange from microsoft that argv is not an array of
**const** TCHAR*
:|
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
toxcct wrote:
strange from microsoft that argv is not an array of const TCHAR*
Yeah. I guess it stays consistent with the old days of C :) There's no const in any of the prototype variations. Beats me! Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Hi guys, I am writing a simple program that the user would like to be able to run from the command prompt. I am wondering how I pass that infromation into the main of my program. For example, if you wish to run Windows explorer from the command line you pass the command "explorer". This will launch Windows explorer and default to showing C:\. However, you can also call explorer and have it open a specific directory "explorer C:\Test\MyTest". My question is this: Is the second part of that simply passed as the argument to main? For example if I wanted my program to specify a string, could I have my main function accept a const char *? I.E.
void main(const char *inputString)
? where inputString would be whatever it is that I have passed immediately after my *.exe name? so the total call would be something like: C:\> stringParser This Is My Test which would hopefully pass a pointer to "This is My Test" into my main argument. Thanks, Joeif you somehow graduate to windows programming you can use GetCommandline api to reterive the command line
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You