int main(int argc, char* argv[])
In this code argv[] is a string not array so how can i use as a array to perform sum operation?
int main(int argc, char* argv[])
In this code argv[] is a string not array so how can i use as a array to perform sum operation?
You can do it like this
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int sum = 0;
int i = 1;
for(;i<argc;++i)
sum += atoi(argv[i]);
printf("%d\n",sum);
return 0;
}
And the result:
$ gcc test.c && ./a.out 1 2 3 4
10