I am trying to create a function in C language that reads a string of command line integers and takes the sum of all the numbers without causing arithmetic overflow/underflow. I understand most of overflow/underflow concepts, but am struggling to apply it to my function.
Here is the code that I have created thus far:
int main(int argc, char * argv[]) {
int sum = 0, i;
if (argc <= 1) {
printf(" Enter integers into command line after command to run .exe file ");
exit(0);
} else {
for (i = 1; i < argc; i++) {
sum += atoi(argv[i]);
}
}
printf(" Sum of all command line arguments is %d ", sum);
}
I am curious to see if this addresses arithmetic overflow/underflow or if it is still missing something.