i m trying to code htoi function in chapter 2.3 for K&R but problem i dunno where to start should i first read all string then after that change each character to its decimal and then add them ? or any better ideas?
MrNoob
24
Posting Whiz in Training
Recommended Answers
Jump to PostTreat it as a variation of K&R's atoi. You should already know that you can step through the string and add the characters like so:
result = radix * result + digit;
If radix is 16, you're converting a hexadecimal value. Now all you need to do …
Jump to Post>but is there a equation to change the characters hex to decimal because
>sometimes if a string got F or A it will just change that to its ascii value.
There is a compact and easy way to do what you want. You can find details on how to do …
All 10 Replies
Narue
5,707
Bad Cop
Team Colleague
MrNoob
24
Posting Whiz in Training
MrNoob
24
Posting Whiz in Training
MrNoob
24
Posting Whiz in Training
Narue
5,707
Bad Cop
Team Colleague
MrNoob
24
Posting Whiz in Training
MrNoob
24
Posting Whiz in Training
Narue
5,707
Bad Cop
Team Colleague
Dave Sinkula
commented:
*whew* My 'playing along at home' version looked very similar. I take that as a Good Thing.
+20
MrNoob
24
Posting Whiz in Training
Narue
5,707
Bad Cop
Team Colleague
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.