Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

atof atol atoi

atof atol atoi

atof atol atoi

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.

tom moses

RE: atof atol atoi

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:
int n;
char c='3';
and away you go.
I could imagine that atof may produce wierd numbers its that whole binary representation of floating point numbers thing.
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.

RE: atof atol atoi

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

tom moses

RE: atof atol atoi

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.
Greg Martin.

RE: atof atol atoi

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.
thanks :)
tom moses

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close