Parsing arguments

Programming, for all ages and all languages.
Post Reply
User avatar
nekros
Member
Member
Posts: 391
Joined: Wed Mar 05, 2008 9:10 pm
Contact:

Parsing arguments

Post 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!
Working On:Bootloader, RWFS Image Program
Leviathan: http://leviathanv.googlecode.com
Kernel:Working on Design Doc
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Re: Parsing arguments

Post 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
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Parsing arguments

Post by Solar »

Is that C or C++?

For C++, I'd strongly suggest boost::program_options.
Every good solution is obvious once you've found it.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Parsing arguments

Post by Combuster »

And fixing your mismatched scope blocks would help too.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
nekros
Member
Member
Posts: 391
Joined: Wed Mar 05, 2008 9:10 pm
Contact:

Re: Parsing arguments

Post by nekros »

Yeah, I just realized accidentally cut to much out.
Working On:Bootloader, RWFS Image Program
Leviathan: http://leviathanv.googlecode.com
Kernel:Working on Design Doc
User avatar
nekros
Member
Member
Posts: 391
Joined: Wed Mar 05, 2008 9:10 pm
Contact:

Re: Parsing arguments

Post by nekros »

Solar wrote:Is that C or C++?

For C++, I'd strongly suggest boost::program_options.
Thanks a bunch.
Working On:Bootloader, RWFS Image Program
Leviathan: http://leviathanv.googlecode.com
Kernel:Working on Design Doc
Post Reply