| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | There`s gotta be an easi |
Hello Jasen!
Replying to a message of Jasen Betts to Neil Heller:
JB> Hi Neil.
JB> 24-Dec-02 23:18:02, Neil Heller wrote to Jasen Betts
NH>> The number is always an integer: "0" <= x <=
"250".
JB> I has a little look in my C++ manual (it's not very good) and I
JB> couldn't find "cstring" so I'm guessing you're just using C strings
JB> (type char*)
I'm assuming that Neil is differentiating between the C-style strings
(herein "cstring") vs the C++-style "string" class.
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 put
NH>> back in the cstring is "1080".
JB> eg:
JB> sprintf(string,"%d",atoi(string)*8);
JB> that's vanilla C code, there may be an OO version of the same
JB> expression but I haven't been using c++ for long enough to figure
JB> oout what it is.
There is - but it's way more convoluted because Neil is not currently using
C++ strings.
string new_val = atoi(old_val) * 8;
That's the easy part. After that, you have to claim the memory:
mystruct->val[1] = strdup(new_val.c_str());
While this doesn't look that convoluted, the amount of stuff happening
under the covers is immense. Further, the first line may not work on some
compilers. Try:
string new_val;
new_val << (atoi(old_val) * 8);
Or on some compilers that won't work either.
istrstream new_val_str;
new_val_str << (atoi(old_val) * 8);
string new_val = // I can't recall offhand how to get the string from
an istrstream.
Good luck!
Darin
C_PLUSPLUS moderator
dmcbride{at}tower.to.org
---
* Origin: Tanktalus' Tower BBS (1:250/102)SEEN-BY: 633/267 270 @PATH: 250/102 99 10/345 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™.