Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
What does this mean in plain English?

C++
int main( int _argc, char *_argv[] )


I have a small if further down that depends on it and i can't figure it out....

C++
if ((argc>=4) && (strcmp(argv[3], "m")==0))
			more=1;
		//**********************************
		result = atoi(argv[2]);
		packetCount=0;
Posted
Updated 8-Mar-22 19:58pm

In plain English, _argc means number of arguments in the command line used at the call of the application, _argv is the array of string arguments in the command line.

The code sample is a bit weird as only arguments #2 and #3 are used; and #0 and #1 ignored. Maybe this is an incomplete sample.

This is how Microsoft explains command line: http://msdn.microsoft.com/en-us/library/17w5ykft.aspx[^].

See also: http://msdn.microsoft.com/en-us/library/6wd819wh.aspx[^].

Here is a simple tutorial on parsing command line: http://www.cplusplus.com/forum/articles/13355/[^].

—SA
 
Share this answer
 
Comments
Member 7766180 21-Aug-11 2:18am    
Thank you so very much! Yeah it is weird, I can't seem to understand the logic behind it. Here is the first part that appears at the begining, maybe this will help?

if (argc<=2)
{
printf("\nUseage...");
printf("\ndood [IP-address] [packet-count] (ml) (o)");
printf("\n--> eyeball ");
return EXIT_SUCCESS;
}
Sergey Alexandrovich Kryukov 21-Aug-11 2:33am    
You're welcome.
If this is not your code you don't have to understand it. Who knows how many stupid things can people write? Make you own code right.
Good luck, call again.
--SA
XTAL256 22-Aug-11 20:56pm    
That first part is checking the size of arguments passed to the application.
In that particular example, the application requires the user to provide at least two arguments. If there are less (if (argc<=2)), it will print an explanation of it's usage and state that it needs at least the arguments [IP-address] and [packet-count]. The 3rd and 4th are optional.
Sergey Alexandrovich Kryukov 22-Aug-11 21:06pm    
If some arguments are optional, they still have to be processed somewhere; maybe below the shown part of code.
Thank you.
--SA
XTAL256 22-Aug-11 21:36pm    
Yes, it looks like those optional args are processed in the first bit of code he posted
Main is a function that returns int, it takes 2 parameters - the first tells it how many arguments were passed on the command line, the second is an array of pointers to each of the arguments.

I.e argc(ount) and argv(alues)
 
Share this answer
 
Comments
Member 7766180 22-Aug-11 10:01am    
Thank you...I understand that, but what is the point of this?
if (argc<=2)
{
printf("\nUseage...");
printf("\ndood [IP-address] [packet-count] (ml) (o)");
printf("\n--> eyeball ");
return EXIT_SUCCESS;
}
thanks ur answers helped me alot
 
Share this answer
 

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