Results 1 to 10 of 10

Thread: long to char ***Resolved

  1. #1

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    long to char ***Resolved

    I know this has probably been asked a thousand times, and I've searched all through the forums and I'm still getting errors..

    Code:
    char Space[255];
    long lNumber;
    
    lNumber = 223538;
    I've tried
    Code:
    sprintf(space, "%i", (int)lNumber);
    
    itoa((int)lNumber, space, 10)
    
    *(long*)space=lNumber;
    And from what I can work out, they either do nothing, or are converting the number into actual ascii characters. I simply want
    Space = "232538";

    as such.

    Thanx
    Last edited by Wak; Nov 2nd, 2002 at 08:47 PM.
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I use ostringstream:
    PHP Code:
    char buffer[10];
    ostringstream mstr(buffer10);
    long lNumber;

    lNumber 223538
    mstr 
    << lNumber << ends;
    cout << mstr.str() << endl
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  3. #3

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    hey

    I don't know if this will make a difference for you, but I'm not writing a console mode application hey..

    I haven't actually tested it, but I notice that a lot of the console mode stuff doesn't work when creating Win Apps (only in regards to the variables that can be declared)
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710

    Re: hey

    Originally posted by Wak
    I don't know if this will make a difference for you, but I'm not writing a console mode application hey..

    I haven't actually tested it, but I notice that a lot of the console mode stuff doesn't work when creating Win Apps (only in regards to the variables that can be declared)
    Itll work, unless you are doing something wrong.

    Z.

  5. #5
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Try _ltoa, as well.

    Z.

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Only thing for console mode there is cout, the oss is just used like it.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    mmm

    if i use _itoa and 10 for the 3rd parameter, the number is too big, base 10 is tooo low...

    and if I use _itoa with 16 for the 3rd parameter, then the number has all the letters that come with base 16...

    How can I just get 223538 in the string?? which base??

    also with hostringstream, are there any specific files that i need to include??

    thanx
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    use base 10, base in a numbering system is the times a digit is worth its digit to the right, the alphabet starting from A are used as digits beyond 9.
    Do you have at least 7 chars in your buffer? can you show your code?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Yes, for ostringstream you must include <sstream>,
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10

    Thread Starter
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    ahh, kule.. I got it :D

    Thanx to everyone that helped... life saver...

    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width