From String to int

I want to grab a number (int) of out a string and use it as address in EEPROM. The code below is not working.

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 is never converted into an 'int' becuase there are no problems when I write

EEPROM.write(2, '8');

If I do a Serial.Print(S), I get '2'. I hope someone can tell me what I'm doing wrong.

I think you answered your own question, there.

The SlotNo variable holds '2', not 2. The '2' is ASCII code 50, so, S would have the value 50, not 2. You are not reading from where you wrote.

To convert a char to an int, subtract '0' from the char:

int S = SlotNo - '0';

Thank you very much! Makes good sense and works!