I am writing a code to produce a C programmed RPN calculator using command line arguments. I am having an issue with the first calculation to be done by the program, as the first element in my array of operators is unknown to me and affects the calculation.
My Command line reads:
$ ./rpn.exe 1 2 3 4 5 + + + +
My array should be {+, +, +, +}
However the output when printed is:
º + + + +
Here is my for loop adding the operators to the array. Operands in my number of Numbers on the cmd line. Is_Op is simply for errors.
for(int c = operands + 1; c < argc; c++)
{
char b = *argv[c];
if(Is_Op(b) == 1)
{
fprintf(stderr, "%c is not an operator", b);
return 1;
}
else
{
operators[c - operands] = b;
}
}
Here is my array printing function. TotalOps is the total no. of operators. And operators[] is an array of them.
for(int count = 0; count <= TotalOps; count++)
{
printf("%c ", operators[count]);
}