1

I am working on postfix calculator to read operators arithmetic operators. An example input is 24 5 6 * +.

This code read * and / operators but not read + and - operators:

while(scanf("%d",&temp))
    ARRAY[i]=temp;
scanf("%s",&operator);
jww
  • 90,984
  • 81
  • 374
  • 818

1 Answers1

1

The + and - characters could be the beginning of a number like "+3" or "-1". So code that is looking for a number will consume those characters. Don't use code to read a number unless you are certain you want to read a number and anything that's not a number is an error.

David Schwartz
  • 173,634
  • 17
  • 200
  • 267