You need to get the array data from arguments that main()
receives. Get each of the elements without getting the 0 which is the name of the executable.
As the argument comes as string , you need to do a conversion with strtol()
.
There are a number of checks that would be good to do, such as whether the number of arguments needed, whether the number conversion worked, or what might be useful for the problem.
You do not need variables to display the sum. But if you're going to use variables for something else, do not make them global, it's hardly ever necessary.
You do not need this static variable, I just did this by limiting the ideone.
#include <stdio.h>
#include <stdlib.h>
static char *argv[] = { "app", "123", "456" }; //gambiarra pra simular a passagem de argumento pela linha de comando
int main(/*int argc, char *argv[] */) {
printf("Soma: %ld", strtol(argv[1], NULL, 10) + strtol(argv[2], NULL, 10));
}
See running on ideone .