#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Command Line Argument in C


    I have two function 'foo' and 'bar' needs to be executed . Both have same definition but different implementation. I have program called 'test' which executes the function 'foo' or 'bar' based on the input argument. Implement your solution in C

    For example,
    $ run test bar - runs the 'bar' function
    $ run test foo - runs the 'foo' function

    this is the question
    I cant understand the question.. plz explain & giv a program for the above question
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    71
    Rep Power
    3
    Originally Posted by clearner007
    I have two function 'foo' and 'bar' needs to be executed . Both have same definition but different implementation. I have program called 'test' which executes the function 'foo' or 'bar' based on the input argument. Implement your solution in C

    For example,
    $ run test bar - runs the 'bar' function
    $ run test foo - runs the 'foo' function

    this is the question
    I cant understand the question.. plz explain & giv a program for the above question
    Just check the command line arguments and then make a decision on what's passed. i.e.

    Code:
    if ( !strcmp(argv[1], "foo") )
    {
    /*call foo*/
    }
    ...

IMN logo majestic logo threadwatch logo seochat tools logo