The first parameter inside main() contains the number of command line arguments. so sizeofargv = 4.
The second parameter inside main() contains the command line arguments as an array of string. so
*argv[3] = sunday
*argv[2] = tuesday
*argv[1] = friday
*argv[0] = sample
Mani said:
(Thu, Jun 23, 2011 12:47:53 AM)
Thanks Arvind.
Prudhvi said:
(Wed, Jul 20, 2011 07:33:42 PM)
Here sample is name of the program how can be it be an argument ?
Yogesh said:
(Sat, Aug 27, 2011 01:16:34 PM)
The first parameter inside main(....)determines the number of cmd line arguments i.e sizeofargv=4.
and second parameter stores the actual parameters in array
i.e.
argv[3] = sunday
argv[2] = tuesday
argv[1] = friday
argv[0] = sample
while loop executed four times. It breaks when value of sizeofargv becomes -1.
Output:
in first execution: argv[3]=sunday
in second execution: argv[2] =tuesday
in third execution: argv[1]=friday
in fourth execution argv[0]=sample
now value of sizeofargv becomes -1 and loop breaks.
Ferissa said:
(Mon, Sep 12, 2011 05:40:08 PM)
Hi pruthvi this is ferissa, I think there is no error when the program name matches with the argument.
Narmada said:
(Wed, Nov 2, 2011 09:57:10 PM)
Pruthvi in c for command line arguments the program name will be consider as first argument as argv[0]. So sample will be stored in argv[0].