I am just begging to use these functions and i had heard that in some curcumstances they will report the wrong int value. does anyone know if this is true or not. thanks.<br>
<br>
tom moses
I'm just using atoi() right now for a cgi based enrolment system(uni project actually but it made me sound important) I haven't come across any problems with it. you should remember to cast your argure ment to an integer though eg:<br>
int n;<br>
char c='3';<br>
n=atoi((int)c);<br>
and away you go.<br>
I could imagine that atof may produce wierd numbers its that whole binary representation of floating point numbers thing.<br>
I've also read that there are alternatives to atoi(), better fucntions I haven't got my book with me but I'll post the details when I get a chance.
Thanks i had just heard that from another kid in my class, i didn't see anything to support that on the program im working on right know. Yeah if you find anything differen't can you post it, i was thinking maybe something that just dumps it to a stdout and then brings it back in as a int. I wrote something similar except i got it to work by putting it in a txt file and then reading it back in. Thanks for the help<br>
<br>
tom moses
Actually, casting to int makes no sense what so ever. atoi and friends are prototyped to take a const char * as an argument, not an int. the main draw back with these functions is they allow for no error checking. The strtol strtod and (int)strtol functions are actually a better choice. If an overflow occurs it sets an error value and returns a value to let you know whether the value was positive or negative. The unconverted portion of the string can be retrieved from the second argument. It is prototyped in stdlib.h as well.<br>
Regards,<br>
Greg Martin.<br>
Hey thanks i tried these functions in my program and they worked really well. It was actually my teacher that recommended to use these functions and was aware of some of the problems with it but said it would be rare. I'll tell him about these in class.<br>
thanks <br>
tom moses
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.