I tried the exercise 5 on page 312 of King's Book C programming A modern approach second edition.
Write a program named sum.c that adds up its command line arguments which are assumed to be integers . Running the program by typing :
sum 8 24 62 should produce the following input
Total : 94
Hint: Use the atoi function to convert each command line argument from string form to integer form
My solution is :
It is running good without problems but I am wondering because it is very small solution with few lines of code . Is there something wrong???? I posted it in order to take some other opinion.Code:#include<stdio.h> #include<stdlib.h> int main(int argc , char *argv[]) { int i , sum=0; for( i = 1; i < argc; i++) sum += atoi(argv[i]); printf("Total: %d\n" , sum); return 0; }
Thank you in advance
Mr Lnx



2Likes
LinkBack URL
About LinkBacks



