lcl wrote:Thanks for commenting GEuser!
I've never used atoi, atof, or atol, I guess they're for converting text to variables, integer, float and long, aren't they?
And yeah, you're right I should do a basic math function video, too.
Just have to study them thoroughly first.
Yep, thats what they do. I used them for my genwave viewer thing to get userinput in variables. Here's a quick review with example:
atoi converts text into an integer.
Example:
In a shoot'em up game I want the user to have the ability to specify the amount of ammo at the start of the game. Player types ammo amount in an input text actor (
txtInputAmmo) and presses an OK button (
buttonOkay) to confirm amount typed in:-
txtInputAmmo (this is a text actor with user input enabled).
buttonOkay (this is the normal actor for okaying ammo typed in)
- Code: Select all
// EVENT: buttonOkay->mouse button down( left)
int ammo=atoi(txtInputAmmo.text);
Now 'ammo' variable can be used with in the program code.
so text 0.12 will produce 0 with atoi, 1sdhgddd gives 1, xcetr gives 0, 21.234 gives 21 so on...
atof converts text into an double.
Example:
- Code: Select all
// EVENT: buttonOkay->mouse button down( left)
double ammo=atof(txtInputAmmo.text);
so text 0.12 will produce 0.12 with atof, 1sdhgddd gives 1, xcetr gives 0, 21.234 gives 21.234 so on...
atol converts text into an long integer.
Example:
- Code: Select all
// EVENT: buttonOkay->mouse button down( left)
double ammo=atol(txtInputAmmo.text);
so text
222222 will produce 222222 with atol,
2222222 gives 2.222222e+06,
22222222 gives 2.222222e+07,
xcetr gives 0
21.234 gives 21 so on...
i don't really use atol so don't see much difference then using atof but I think it allows for much bigger integer values, I tried
unsigned long int and other variants but get a big negative exponent value some thing crazy like 5.55444343e-323. This is a skydereign moment. Sky. help!
[EDIT] my bad for
atol i didn't change the %g bit to %i so long int gives max value of 2147483647 anything higher will return this value (although this appears to be same for atoi ... mmmh?