quote:
Originally posted by Verte
[recently a friend couldn't work out how to convert a string to an integer- turns out you can subtract zero to do this. Just too strange].
That would be subtracting the character '0'. That's possible in C/C++ as well.
For example:
code:
int atoi(const char * pstr) {
int i;
int nRet = 0;
for (i = 0; ; i++) {
if (pstr[i]==0)
break;
if (pstr[i]>='0' && pstr[i]<='9') {
nRet*=10;
nRet+=pstr[i]-'0';
}
else return 0;
}
return nRet;
}