Need help in C++ command line operations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AmmarN
    New Member
    • Mar 2007
    • 18

    Need help in C++ command line operations

    Hi all,

    I have a c++ programme that intakes a binary file and performs various operations on it. I am not gonna get in to the details of the operations, currently i specify the order in which the operations take place by calling different functions the way i write the main function. My question is -- Is there a way that a user can call different functions from this application from the command line.
    For example.

    say i have 3 functions namely F1 , F2, F3.

    now fromthe command line once i have started the application can i call
    F2 ----(F2 does something and produces result) and then I call
    F3 and similarly the other functions in the order I like.

    Thanks for all the help in advance. If my question is not clear enough plz let me know.

    Ammar.
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    I don't know whether this is quite what you mean, but you can specify commandline paramters when you run your program eg:

    Code:
    a.out F1
    This can be retreived in main :

    Code:
    int main(int argc, char argv[])
    {
      if(argc > 1) // The first element is this program
      {
        for(int i=1; i< argc; i++) 
        {
          if((strcmp(argv[i], "F1")==0)
          {
             printf("Whohoo");
          }
        }
      }
    }
    Obviously you can add other checks (you might like to make a function to do it).

    Otherwise (if you want these commands to be entered WHILE the programming is running), (cin) input will appear to come from teh commandline (though you won't be able to do anything else from the commandline at the time)

    Hope this helpes

    Comment

    • AmmarN
      New Member
      • Mar 2007
      • 18

      #3
      Thank you for your reply.

      You are right i actually would like to call the functions while the programme is running and i understand that i wont be able to do anything else at the command line while the prograame is running. Its an application so i wanna run the programme first and then call different functions while the programme is running such as:

      a.out Open (filename)
      a.out CallF1 (x,y,z)
      (after F1 produces its result e.g "Woohoohoo" then
      a.out CallF2 (a,b,c)
      .
      .
      .
      and Finally

      a.out Quit.

      meaning call different functions from the command line with the parameters.
      Any help with the structure of the main function to acheive the above will be highly appreciated.

      Comment

      Working...