im writing a program that adds up command line arguments, how can i account for a situation where there are no arguments at all?
#include <iostream>
using namespace std;
int main(int argc,char *argv[]){
int answer = atoi(argv[1]);
if (argc=='0'){
cout << '0';
}
else if (argc == '1')
cout << answer;
else {
for (int j=2; j < argc; j++){
answer += atoi(argv[j]);
}
cout << answer;
}
return 0;
}
when i run the program w/o arguments i get a memory fault(coredump) error