From String to int
i want grab number (int) of out string , use address in eeprom. code below not working.
i'm pretty sure s never converted 'int' becuase there no problems when write
eeprom.write(2, '8');
if serial.print(s), '2'. hope can tell me i'm doing wrong.
code: [select]
instring = #num2;
char slotno = instring.charat(4); //returns '2'
int s(slotno);
eeprom.write(s, '8');
char value = eeprom.read(2);
serial.println(value, byte);
i'm pretty sure s never converted 'int' becuase there no problems when write
eeprom.write(2, '8');
if serial.print(s), '2'. hope can tell me i'm doing wrong.
i think answered own question, there.
the slotno variable holds '2', not 2. '2' ascii code 50, so, s have value 50, not 2. not reading wrote.
to convert char int, subtract '0' char:
int s = slotno - '0';
the slotno variable holds '2', not 2. '2' ascii code 50, so, s have value 50, not 2. not reading wrote.
to convert char int, subtract '0' char:
int s = slotno - '0';
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > From String to int
arduino
Comments
Post a Comment