Telling if characters in a string are numbers

I’m trying to make a RPN calculator out of an arduino. I have things where they split up the expression 1 2 3 4 + into different number/ commands to add to the stack. I need to differentiate between numbers (to add to the stack) and commands (to manipulate the stack)
Here’s my

 #include <StackList.h>
StackList <int> stack;
String work;
String readString;
void setup() {
  Serial.begin(9600);
}

void loop() {

  while (Serial.available()) {
    delay(10);
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c;
  }

  if (readString.length() >0) {
    while(readString.length()!=0) {
      readString.trim();                                        //Just in case
      readString.concat(' ');                                   //so the next function can work for the last argument
      work=readString.substring(0,readString.indexOf(' '));     //finds the data and operations
      
      
      if(work[0]=='0'||'1'||'2'||'3'||'4'||'5'||'6'||'7'||'8'||'9') {
        Serial.println(work);        //output of the equation
      }
      readString=readString.substring(readString.indexOf(' ')); //removes the used argument
      readString=readString.trim();                             //removes white space at the beginning and end
    }
  }
}

Any help would be greatly appriciated.
Thanks,
Isaac

This…

      if(work[0]=='0'||'1'||'2'||'3'||'4'||'5'||'6'||'7'||'8'||'9') {

…doesn’t do what you want or expect. Try this instead…

      if ( (work[0] >= '0') && (work[0] <= '9') ) {

You should really use one of the standard functions such as isdigit(x) in ctype.h for this.

You should really use one of the standard functions such as isdigit(x) in ctype.h for this

And if this returns success, read it straight into a numeric variable (rather than a string) with something like

int a=Serial.read()-'0'

For multi-digit numbers (assuming you are using the space character as your separator), you'd need a Serial.peek () to see if you have another digit still to come.

As a matter of curiosity, how do you deal with negative numbers in RPN?

You should really use one of the standard functions such as isdigit(x) in ctype.h for this.

Thanks Andy. working as expected.

And if this returns success, read it straight into a numeric variable (rather than a string) with something like

Code: int a=Serial.read()-'0'

For multi-digit numbers (assuming you are using the space character as your separator), you'd need a Serial.peek () to see if you have another digit still to come.

As a matter of curiosity, how do you deal with negative numbers in RPN?

Right now I'm just using the serial for simplicity's sake. I'm going to use a keypad and glcd in the future, so I'll use atoi() or .toInt(). For negative numbers I'll use:

isdigit(work[0]) || work[0]=='-'  && isdigit(work[1])

As a matter of curiosity, how do you deal with negative numbers in RPN?

For negative numbers I'll use: Code: isdigit(work[0]) || work[0]=='-' && isdigit(work[1])

argh sorry djc. I'm running low on sleep (staying up coding :) ) but on calculators like the hp48 you use 100 neg which negates the number. It is the hp48 that inspired me to write this program.