By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,403 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,403 IT Pros & Developers. It's quick & easy.

how to convert"-123" pointer string to int -123 without using atoi

P: 2
a function which takes a string (pointer to char) as a parameter and returns the
integer equivalent.str2int("1658") would return the value 1658
To improve your program change the function to accept strings with a leading minus sign toi ndicate a negative number.
One last improvement might be to print a warning if the string represents a numberthat is outside the range of an int.
Dec 4 '07 #1
Share this Question
Share on Google+
4 Replies


gpraghuram
Expert 100+
P: 1,275
a function which takes a string (pointer to char) as a parameter and returns the
integer equivalent.str2int("1658") would return the value 1658
To improve your program change the function to accept strings with a leading minus sign toi ndicate a negative number.
One last improvement might be to print a warning if the string represents a numberthat is outside the range of an int.

I think you have to write your own atoi function.
You may get atoi code easily by searching in the net.
Post again if your requirement is different.
Raghuram
Dec 4 '07 #2

P: 90
I never liked atoi, is it standard?

I always used sscanf().
Dec 4 '07 #3

P: 72
Code removed per posting guidelines
Hope this will help you.

Thanks,
Manjunath
Dec 4 '07 #4

weaknessforcats
Expert Mod 5K+
P: 9,197
Why all this complex code???

The requirment was that atoi() couldn't be used. So why not just call strol() and call it a day???
Dec 4 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.