Click here to Skip to main content
15,902,275 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
i want to write to a console application that works like that :
<br />
reza -m <br />

does a big job,and
<br />
reza -n<br />

does another big job but totally unrelated to previous job.and so on
i don't mean how to recognize which argument entered,i mean how to i write these jobs?
should i write them as an executable program and call them via the main program? or another ways?
Posted
Updated 26-Jul-12 10:28am
v3
Comments
[no name] 26-Jul-12 15:38pm    
You question makes no sense. If you can differentiate between -m and -n then if the argument is -m do "the big job" and if -n then "do smaller unrelated job". What do mean by "how to i write these jobs"? They are your jobs how are we supposed to know what they are?
Sergey Alexandrovich Kryukov 26-Jul-12 15:49pm    
I think this is nothing but a question about command line parameters, poorly formulated; I answered, please see.
--SA
[no name] 26-Jul-12 15:53pm    
No, he stated in his question that he knows how to recognize the arguments.
Sergey Alexandrovich Kryukov 27-Jul-12 16:56pm    
You are right, I see. (Not show he actually knows though...)
--SA
pasztorpisti 26-Jul-12 15:40pm    
This isn't clear for me. Tell us what do you want to do please.

The arguments are passed to your C++ application (no matter if it is a console application or not; it also could be the windowed UI application, or the application with no screen input/output at all) through its entry point.

Please see:
http://en.wikipedia.org/wiki/Main_function#C_and_C.2B.2B[^].

With C++, to allow for passing command line to your code, you need to use the entry-point function with one of the following signatures:
C++
int main(int argc, char **argv);
int main(int argc, char *argv[]);

//Windows-only
int main(int argc, char **argv, char **envp);

//Apple-only:
int main(int argc, char **argv, char **envp, char **apple);

The actual values for the function arguments argc and argv will be taken from the command line actually entered by the customers (directly for from script, Shell, Windows *.lnk file, etc.) by the system loaded and passed to your entry-point function. You application code should use them; parse the command line parameters to figure out the options.

Note: The "entry-point" function supplied by your application code can have different name and even somewhat different signature. It might happen when you are using certain framework defines main internally and calls some other function (such as _tmain(int argc, _TCHAR* argv[]) where you can use different character types, depending on compilation option) which your application should supply. The idea is the same or very close, anyway.

—SA
 
Share this answer
 
v5
Comments
Reza Oruji 26-Jul-12 16:20pm    
thanks,my question was Ambiguous
Sergey Alexandrovich Kryukov 26-Jul-12 16:43pm    
That means I took a right guess... :-)
You are welcome. Good luck, call again.
--SA
CPallini 26-Jul-12 16:27pm    
5.
Sergey Alexandrovich Kryukov 26-Jul-12 16:43pm    
Thank you, Carlo.
--SA
pasztorpisti 26-Jul-12 18:32pm    
+5 Achievement Unlocked: Mind Reader :D
I would write two console applications: the rezam and the rezan (if I wouldn't able to find better names).
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 27-Jul-12 0:54am    
It could make perfect sense; and if they have some common code, they can use one more module, a common DLL. My 5.
--SA
CPallini 27-Jul-12 3:42am    
Thank you.
If they're unrelated, you should probably think about just making them separate applications, and forget about command line parameters altogether.

If you really want to go that route, you have two options as I see it:
1) You make a single monolithic program, and separate the jobs in that program (ideally into separate classes/functions).
2) You make a program that does nothing but interpret the command line arguments, and have that program launch the appropriate program for the job

I think personally I'd recommend option 2 if you feel you must go this route.
 
Share this answer
 
Comments
pasztorpisti 26-Jul-12 16:22pm    
Not sure what the question is so can't decide if this is a good answer or not but just 5ed it because it says something wise.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900