So at first i was trying to use character at index, then convert it to nsnumber, and then get the int value, but for 9 i got a value of 57. So I knew what was going wrong, I’m getting the int of the character itself.
So I read a little, and found atoi, but I get this error, that doesnt crash my app jsut pauses it.
My code is:
int current = atoi([startSquares characterAtIndex: i]);
Now startSquares is a big string full of numbers, and this above line is in a for loop where i goes from 0 to 99.
57 is ASCII for the digit
'9'. Assuming that by the “value of the char” you mean “the numeric value of the digit the char represents”, you can use the simple trick available in ASCII:This trick works, because all digits are encoded in order starting with the digit zero (ASCII code 48). So when you subtract
'0'(which is another way to write 48) from 57, you get 9, the value of the digit'9'.