So I'm pretty new to C and am trying to learn how to make it take command line inputs, I typed it in what I'm hoping is the correct syntax and I'm trying to get it so you type in 2 numbers and it returns those two numbers added together. The program does compile but when I try to run it, it takes the parameters and they're printed completely wrong, almost as if they're printing the memory addresses.
Here is my code:
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
int addition(int a, int b);
int main(int argc, char *argv[]) {
if(argc != 3) {
printf("You must enter 2 numbers!");
return TRUE;
}
else {
int answer = addition((int)*(argv[0]), (int)*(argv[1]));
printf("%d + %d = %d", argv[0], argv[1], answer);
return FALSE;
}
}
int addition(int a, int b) {
return a + b;
}
So what am I doing wrong? The output when I put in 2 3 is:
155 + 50 = 165