// Convert command-line arguments to integers and print their sum. // // No check is made that the command-line arguments are actually integers. // See strtol for a more powerful library function which would allow checking. // // COMP1511 lecture example // Andrew Taylor - andrewt@unsw.edu.au // July 2021 #include #include int main(int argc, char *argv[]) { int sum = 0; int argument = 1; while (argument < argc) { // convert string to integer int n = atoi(argv[argument]); // you could use `strtol` instead of `atoi` like this // int n = strtol(argv[argument], NULL, 10); sum = sum + n; argument= argument + 1; } printf("Total is %d\n", sum); return 0; }