Advertisement

Command line parameter

Started by December 30, 2000 04:07 PM
5 comments, last by paulkp 24 years, 1 month ago
I need to get one command line parameter -nv in my program made with DJGPP, but how? I don''t know how getopt works and the example source doesn''t work either.
Well, getopt is actually provided primarily as a way to help streamline porting linux/unix apps to dos. The easiest way to do this is to simply write your own code to check the command line parameters.
Advertisement
If I understand correctly, does this help?
  #include <iostream>#include <string>#include <vector>int main(int argc, char** argv, char** env){	using namespace std;	vector< string >	cmdStack;	while(*argv)	{		cmdStack.push_back(*argv++);	}	for(vector<string>::iterator idx = cmdStack.begin(); idx < cmdStack.end(); idx++)	{		if(*idx == "-nv")		{			cout << "-nv passed as parameter" << endl;		}	}	return 0;}  



YAP-YFIO,
deadlinegrunt

~deadlinegrunt

Here I know this works..

  int main(int argc, char **argv){	if (argc == 1)	{		cout << "Just the filename was entered" << endl;                return 0;	}		if (argc == 2)	{		if (!strcmp(argv[1], "-compile"))		{			cout << "The Filename and -compile where entered" << endl;			return 0;		}        }}  
------------------------------------------------------------I wrote the best video game ever, then I woke up...
getopt is really easy, although I have only used the linux version but I think they work the same, so telnet to your nearest linux server and type "man getopt"

Gyzmo
=======================
Meddle not in the affairs of dragons for you are crunchy and go well with toast.
Gyzmo=============================="Well is the world standard" - The Alchemist"Not in Canada!" - jonnyfish
Or if you have Rhide you can use the libc reference (you can find it in the help menu) to find out how to use getopt()
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Advertisement
quote:
Original post by Muzzafarath
Or if you have Rhide you can use the libc reference (you can find it in the help menu) to find out how to use getopt()


Thanks for all help. I found out the solution from one of my older sources.. there the second parameter of int main() is actually char *argv[] but I guess it''s same as char **argv

I have Rhide, but the example source for getopt() doesn''t work.
I don''t have access to Linux. Thank god

This topic is closed to new replies.

Advertisement