Page 1 of 1

Parsing arguments

Posted: Sun Mar 29, 2009 9:00 pm
by nekros
So I'm parsing the command line arguments for my rwfs prog. For some reason, it only gets the first "-d" + args. I'm not giving you the actual code within the switch(there is a lot of it). Help appreciated.

Code: Select all

	for(int i = 1; i<argc; i++)//parse arguments
	{
		int charc = 0;
		switch(argv[i][0])
		{
			case '-':
				charc++;
				switch(argv[i][1])
				{

		}
	}//done with all that parsing crap, lets do some work!

Re: Parsing arguments

Posted: Sun Mar 29, 2009 9:26 pm
by DeletedAccount
Hi,
In windows parse the LPSTR lpCmdLine parameter , There also GetCommandLine functions, In Linux use get_opt family of functions . You code seems to be fine and seems to do whatever you described . It would be helpful if you can show the entire thing . Anyways , try using a debugger to debug even before that.

Regards
Shrek

Re: Parsing arguments

Posted: Sun Mar 29, 2009 10:24 pm
by Solar
Is that C or C++?

For C++, I'd strongly suggest boost::program_options.

Re: Parsing arguments

Posted: Mon Mar 30, 2009 2:23 am
by Combuster
And fixing your mismatched scope blocks would help too.

Re: Parsing arguments

Posted: Mon Mar 30, 2009 7:19 am
by nekros
Yeah, I just realized accidentally cut to much out.

Re: Parsing arguments

Posted: Mon Mar 30, 2009 7:43 am
by nekros
Solar wrote:Is that C or C++?

For C++, I'd strongly suggest boost::program_options.
Thanks a bunch.