does atoi () return zero if the string only contains letters?
am I right?, the source I got it from was a little dim
[edited by - kappa the imp on January 12, 2003 9:32:05 AM]
I don''t know, but you could just test it out. Pass it a string with letters and check the return value.
C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!
Yes, it will return zero. It will read until it finds a non-numeric character. So "123" will return 123, "12kdjd" will return "12", and "alskdjl" will return 0.
quote: Original post by Pipo DeClown
what about "0"? :D
then you would go crazy...
how about doing this?
char foo[10] = "0";int intfoo;intfoo = atoi(foo); // if this is wrong sorry, i''m not too sure how it''s calledif(intfoo == 0) { if(foo[0] == ''0'') { // intfoo is correct! do something } else { // intfoo is invalid, do error code }}
C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement