OK: Some slight problems here:
argc
contains the number of arguments, not
argv
. Change to:
for(int i=1;i<argc;++i)
and
argv
contains the arguments themselves, not
argc
. Change to:
total=total+atoi(argv[i]);
And all should be well.
[edit]And take out the > symbol on the end of your for loop! (If it is really there...) - OriginalGriff[/edit]
Nuri Ismail correctly suggested:
the loop must start from 1 (int i = 1) and 'argc' must be at least 3, because 'argv[0]' is reserved for the process name. Example cmd line: 'my_prog.exe 5 6' -> argv[0] = my_prog.exe, argv[1] = 5 and argv[2] = 6. :thumbsup:
I have updated my response to illustrate that.
It was also (very correctly) pointed out that you should check your inputs for:
Number of arguments - argc should be equal to three or you have a problem!
Valid digts - is the argument actually a number?
If you need help with that, please ask again in another question!