Telling if characters in a string are numbers


i'm trying make rpn calculator out of arduino.  i have things split expression
code: [select]
1 2 3 4 + different number/ commands add stack. need differentiate between numbers (to add stack) , commands (to manipulate stack)
here's
code: [select]
#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 1 byte serial buffer
   readstring += c;
 }

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

any appriciated.
thanks,
isaac


this...

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

...doesn't want or expect.  try instead...

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


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Telling if characters in a string are numbers


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums