|
-
Feb 28th, 2001, 11:04 AM
#1
Thread Starter
Hyperactive Member
-
Feb 28th, 2001, 11:16 AM
#2
Frenzied Member
Well basically, say at the command line you type
Code:
C:\DirName\FileName.exe -argthing -something
In this case you have supplied 2 arguments to your program (your program is FileName.exe, and it's located in C:\DirName\)
So from your description (I haven't used command line parameters before), argc will be 3, argv[0] will be the char* string "C:\DirName\FileName.exe", argv[1] will be "-argthing" and argv[2] will be "-something". What you do with these parameters is really up to you. Generally you would check if they were recognised keywords, and if they aren't either ignore them (if your program can do some default action) or print out a description of acceptable arguments.
So essentially, argc is the number of arguments supplied +1, argv[0] is the file path and file name that the user typed, and argv[1] to argv[argc-1] are the arguments you want.
Harry.
"From one thing, know ten thousand things."
-
Feb 28th, 2001, 02:48 PM
#3
Monday Morning Lunatic
Actually, argv[0] is the full path, not just what was typed.
Under windows, VC++ also supports:
Code:
int main(int argc, char **argv, char **envv)
NB: I used **argv out of personal preference, but *argv[] is still perfectly legal. envv stores an array of environment variables, so you don't need to use getenv()...not totally sure about the usefulness of envv, actually
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 28th, 2001, 06:41 PM
#4
Thread Starter
Hyperactive Member
So...
So, sorry, but it still not really clear. BTW, do i really need them? if later i want to go into windows programming?
Thanx
Amon Ra
The Power of Learning.
-
Feb 28th, 2001, 06:45 PM
#5
Frenzied Member
You don't need them unless you want to take command line parameters.
Harry.
"From one thing, know ten thousand things."
-
Feb 28th, 2001, 06:45 PM
#6
Monday Morning Lunatic
Hate to be the one to break this to you, but in Windows programming main is not used, and is replaced by an even more painful creature:
Code:
int WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow);
You don't have to have argc, argv, and envv. In fact I don't use envv at all, and I don't know of any code that does. If you need to process your program's arguments, then you need argc and argv.
Code:
#include <iostream.h>
int main(int argc, char **argv) {
int i;
for(i = 0; i < argc; i++) {
cout << i << ":" << argv[i] << endl;
}
return 0;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 28th, 2001, 07:23 PM
#7
Thread Starter
Hyperactive Member
Hmmm...
LOL Thanks for the positive intro, parksie 
Anyways, so i will just leave that aside. The main thing i am supposed to know to make win program is classes, right?
Amon Ra
The Power of Learning.
-
Feb 28th, 2001, 07:52 PM
#8
Frenzied Member
Well you can make Windows programs with just straight C (I think) so classes are useful but not essential. You will need to know all about pointers though.
Harry.
"From one thing, know ten thousand things."
-
Feb 28th, 2001, 08:01 PM
#9
Thread Starter
Hyperactive Member
Pointers
Right now, the only thing i can do with pointers is get the value in a specific address, or get the actual address of a variable in the memory. Is there more than that?(i am sure there is
Amon Ra
The Power of Learning.
-
Feb 28th, 2001, 09:36 PM
#10
Thread Starter
Hyperactive Member
??
Please, again, when should i judje myself as able to do windows programming??
Dont just read this, please tell me Thanx
Amon Ra
The Power of Learning.
-
Feb 28th, 2001, 11:09 PM
#11
Frenzied Member
Umm, well I can't really tell you, since I don't do much Windows programming, mainly plain C++ and DirectX. Do you understand the relationships between pointers, arrays and strings? That's probably the hardest bit to get to grips with, although it's one of the basics.
If you think you know more or less all about console programming, then you will know enough to start Windows programming. It's just a matter of understanding the language pretty well before you dive into Windows apps and get confused, because there are a lot of aspects to Windows programming that are not really anything to do with C++, they're to do with the O/S.
Harry.
"From one thing, know ten thousand things."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|