TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: Neil Heller
from: Jasen Betts
date: 2002-12-25 19:33:40
subject: There`s gotta be an easi

Hi Neil.

24-Dec-02 23:18:02, Neil Heller wrote to Jasen Betts


 JB>> we need details. is the number always in base-10 representation
 JB>> (or is octal or hex OK)? how about E-notation?

 NH> I don't think you're looking at the correct details.  The question
 NH> I had involved pulling a value out of a cstring (example: "120"),
 NH> manipulating it mathematically and then putting a representation
 NH> back into the cstring (example:  "12").

ah... I idnd't realise the "divide by 10" was an "for
example" I thought
it was part of the problem...

 JB>> Is it safe to assume that a "double" can hold the number ?

 NH> The number is always an integer:  "0" <= x <=
"250".

I has a little look in my C++ manual (it's not very good) and I couldn't
find "cstring" so I'm guessing you're just using C strings (type char*)

 NH>> I must divide these numbers by 10. I then must place that value
 NH>> back into the cstring (where I originally got it).

if there's always going to be room in the original string for the result,
digits just use sprintf (or itoa etc..)

 NH> The way it turned out, what must be done is the multiply the
 NH> number by 8.  That is, if the cstring was "135", what needs to be
 NH> put back in the cstring is "1080".

eg:
  sprintf(string,"%d",atoi(string)*8);

that's vanilla C code, there may be an OO version of the same expression but
I haven't been using c++ for long enough to figure oout what it is.

 -=> Bye <=-

---
* Origin: Success is a journey, not a destination. (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 123/500 106/1 379/1 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.