I'm writing not to ask for help, but rather giving help, though it wasn't asked for.


I wanted to share some tricky stuff about variable conversion, because it's not always evident...
You all probably know (or if you don't, then that's why I'm writing it down) that it's easy to convert strings into other variables through atof, atoi, atol
- Code: Select all
someactor.textNumber = atoi(text);
That gives someactor's text the integer atoi converted from the current actor's text...
- Code: Select all
somevar = atof(text);
Saves the double/floating point value into a variable from the current actor's text...
atol isn't that important because it converts to long int from text, but we all use simple integers instead of that anyway...
The question arises, as to how to convert back to strings??? Let's say I want to put a number into a string variable!
Searching through the functions you may say there's no such function that will do the conversion for me!
Or is there?
sprintf saves the day!
- Code: Select all
sprintf(text, "%i", someinteger);
sprintf(text, "%f", somefloat);
Through the variable names I've already told you how it works!
Most of you may know this, but I thought I'd post this anyway, for anybody new if they'd want to raise this question. Now it's easier for us to refer them to this post...
