I am using C Programming Language.
I write a simple code for arithmetic operations using command-line arguments, but i have a simple problem. when i open the command-line console from windows to test my program. the multiply operation not worked but the other operations work successfully.
here is my code:
#include <stdio.h>
int main(int argc, char *argv[])
{
if (argc != 4)
{
printf("Error: you must use 4 arguments\n\n");
return 1;
}
int x = argv[1][0] - '0';
int y = argv[3][0] - '0';
int z = 0;
if (strcmp(argv[2], "+") == 0)
z = x + y;
else if (strcmp(argv[2], "-") == 0)
z = x - y;
else if (strcmp(argv[2], "*") == 0)
z = x * y;
else
z = x / y;
printf("Result = %d\n\n", z);
return 0;
}