According to the previous answer, I think this is what you want:
#include <stdio.h>
#include <stdlib.h>
int soma(int a, int b) {
return a + b;
}
int main(int argc, char *argv[]) {
printf("Soma: %d", soma((int)strtol(argv[1], NULL, 10) + (int)strtol(argv[2], NULL, 10)));
}
I put in the Github for future reference.
But if you want to make the separate impression (I wouldn’t, but I wouldn’t even have this auxiliary function either:
#include <stdio.h>
#include <stdlib.h>
void soma(int a, int b) {
printf("%d\n", a + b);
}
int main(int argc, char *argv[]) {
printf("Soma: ");
soma((int)strtol(argv[1], NULL, 10) + (int)strtol(argv[2], NULL, 10))
}
I put in the Github for future reference.
So it would make a little more sense:
#include <stdio.h>
#include <stdlib.h>
int soma(char *primeiro, char *segundo) {
return (int)strtol(primeiro, NULL, 10) + (int)strtol(segundo, NULL, 10));
}
int main(int argc, char *argv[]) {
printf("Soma: %d", soma(argv[1], argv[2]));
}
I put in the Github for future reference.
You must not pass the "sum". If the intention is to call the function according to the text, and is not in the question, there complicates a little, or rather, depending on the required technique.
What is this
< soma
in the call to the application ? What is your goal ? The idea is to be able to specify the operation directly in the call ?– Isac
the goal is to pass a value to "a" and "b" and present the sum by calling the main program first
– user48571
And why the text
soma
and the<
are included in the call ?– Isac
the character "<" is to access a zone in the program I think(the function) but it is not to present the result. When I do . /example < sum 3 4 should write as result "The sum =7"
– user48571
@user48571 The answer solved your question? Do you think you can accept it? See [tour] if you don’t know how to do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.
– Maniero