By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,925 Members | 1,129 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,925 IT Pros & Developers. It's quick & easy.

Need help in C++ command line operations

P: 18
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.
Mar 23 '07 #1
Share this Question
Share on Google+
2 Replies


DeMan
100+
P: 1,806
I don't know whether this is quite what you mean, but you can specify commandline paramters when you run your program eg:

Expand|Select|Wrap|Line Numbers
  1. a.out F1
  2.  
This can be retreived in main :

Expand|Select|Wrap|Line Numbers
  1. int main(int argc, char argv[])
  2. {
  3.   if(argc > 1) // The first element is this program
  4.   {
  5.     for(int i=1; i< argc; i++) 
  6.     {
  7.       if((strcmp(argv[i], "F1")==0)
  8.       {
  9.          printf("Whohoo");
  10.       }
  11.     }
  12.   }
  13. }
  14.  
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
Mar 23 '07 #2

P: 18
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.
Mar 26 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.