Date: Wed, 27 May 1998 13:06:28 +0200 (MET DST) From: Olivier Perron To: Clint Allen Cc: djgpp AT delorie DOT com Subject: Re: C command line options In-Reply-To: Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Wed, 27 May 1998, Clint Allen wrote: > Anyone who can help on this? > I am trying to use command line options in my program. Here's what I've got > so far: > > int main(int argc, char* argv[]) > { > // Declare/init. variables > int title_on; > > // Command line option procedure > if (argc == 1) > { > title_on = 1; > } > else > { > if (argv[1] == "/nts") > title_on = 0; > else if (argv[1] == "/?") > { > puts("Command line options"); > puts("-----------------------"); > puts("/? Display this list"); > puts("/nts No title screen"); > return 0; > } > else > { > puts("Invalid command line option. Use \"/?\" to see valid options."); > return 0; > } > } > > The problem is that whenever one of the valid options is entered, the > comparison statements (such as--if (argv[1] == "/nts")) don't work. In > other words, even though argv[1] DOES equal "/nts", the program goes past > the "if" statement as if it didn't. Am I overlooking the obvious here, or > is my compiler screwed? BTW, I'm using DJGPP & RHIDE. All help is greatly > appreciated. > __________________________________________________________________ If the first argument *IS* "/nts" then argv[1] points (yes, it is a pointer !) to the first character of the string "/nts". This means that *argv[1] = '/'. If you want to make a comparison between the string pointed to by argv[1] and "/nts" you have to use a statement like : if(strcmp(argv[1], "/nts") == 0) Olivier Perron.