If you carefully look at this example you will see with atoi when it runs into a string it gives the integer value of 0. So I was wondering how you tell the difference between the integer value of 0 and a string that got converted to 0.

http://www.tutorialspoint.com/c_standard_library/c_function_atoi.htm

Recommended Answers

All 3 Replies

You can't tell from return value from atoi alone. If it returns 0, it's easy enough to check if the string itself is actually "0" (i.e., '0' followed by '\0').

That makes sense :). Thank you.

You've found one problem with atoi. Please read this for more.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.