Jump to content

Creating invoking commands?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
Lokantis

Lokantis

    Newbie

  • Members
  • PipPip
  • 17 posts
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

#2
Lance

Lance

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts
if you are in Linux/unix environment, libgetopt might be available to you:

refer to : [link]http://swoolley.org/man.cgi/3/getopt[/link]

#3
Lokantis

Lokantis

    Newbie

  • Members
  • PipPip
  • 17 posts
I am using Windows

#4
Phoenixz

Phoenixz

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 256 posts
Using:
strcmp
if
else
Posted Image

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
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
    }
  }
}


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
Lance

Lance

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 276 posts

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