How do I make it so that if you type something like "tr.exe -d" it will execute a certain function but if you type "tr.exe -s" it will execute a different function? Is there a good way or do I just use argv and if statements?
BTW I am using C and gcc compiler
Creating invoking commands?
Started by Lokantis, Feb 03 2009 09:10 AM
5 replies to this topic
#1
Posted 03 February 2009 - 09:10 AM
|
|
|
#2
Posted 03 February 2009 - 09:39 AM
if you are in Linux/unix environment, libgetopt might be available to you:
refer to : [link]http://swoolley.org/man.cgi/3/getopt[/link]
refer to : [link]http://swoolley.org/man.cgi/3/getopt[/link]
#3
Posted 03 February 2009 - 09:57 AM
I am using Windows
#4
Posted 03 February 2009 - 10:38 AM
#5
Posted 03 February 2009 - 12:04 PM
You're talking about using command-line arguments.
#include <stdio.h>
int main( int argc, const char* argv[] )
{
if (argc > 0 )
{
if (argv[1] = "-d")
{
//do -d stuff
}
else if (argv[1] = "-s")
{
//do -s stuff
}
}
}
#6
Posted 03 February 2009 - 12:11 PM
Lokantis said:
I am using Windows
Then parse it yourself. No big deal if your options are not extremely complicated. Refer to WingedPanther's pseudo-code.
You may consider using strcmp, stricmp, etc


Sign In
Create Account


Back to top










