converting a number to a string - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

converting a number to a string

In C on a Macintosh I used to call a function, NumToString(), to convert a long number to a string, so that I could include calculated numbers on buttons. I am trying to learn Windows XP and it is so different.

Does anyone know how to convert numbers to strings or should I get my head down and do the work myself?

Comments

  • GiantGiant Posts: 225Member


    Hi.
    Windows XP is a operating system, not a programming language. I am presuming that you are learning Visual C++, whcih is running on XP.
    If this is the case try using itoa() "int_to_ascii"to convert ints to an ascii string or atoi() "ascii_to_int" to to the oposite.



    The Giant
    Member of the Stupid Coders
    http://www.stupidcoders.cjb.net

    "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." --Albert Einstein

  • Bob SomervilleBob Somerville Posts: 13Member
    :
    :
    : Hi.
    : Windows XP is a operating system, not a programming language. I am presuming that you are learning Visual C++, whcih is running on XP.
    : If this is the case try using itoa() "int_to_ascii"to convert ints to an ascii string or atoi() "ascii_to_int" to to the oposite.
    :
    :
    :
    : The Giant
    : Member of the Stupid Coders
    : http://www.stupidcoders.cjb.net
    :
    : "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." --Albert Einstein
    :
    :

  • Bob SomervilleBob Somerville Posts: 13Member
    : :
    : :
    : : Hi.
    : : Windows XP is a operating system, not a programming language. I am presuming that you are learning Visual C++, whcih is running on XP.
    : : If this is the case try using itoa() "int_to_ascii"to convert ints to an ascii string or atoi() "ascii_to_int" to to the oposite.
    : :
    : :
    : :
    : : The Giant
    : : Member of the Stupid Coders
    : : http://www.stupidcoders.cjb.net
    : :
    : : "Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." --Albert Einstein
    : :
    : :
    : Hi,

    I seem to have re-posted your reply instead of replying to you and I may even be doing that again - sorry - just a beginner.

    I used to write in C on a Mac and I am using Codewarrior to write in C on a PC running Windows XP. I could try learning C++ on my new PC but I think that converting from Mac to Windows is hard enough for me without learning a new language as well.

    Perhaps itoa() will work in C?? I can investigate when I get home.

    Thanks,

    Bob
    :

  • Eric TetzEric Tetz Posts: 2,141Member
    : Does anyone know how to convert numbers to strings or should I get my head down and do the work myself?
    [code=ffffff]
    [color=000080]int[/color] num = [color=bb0000]1234[/color];
    [color=000080]char[/color] str[[color=bb0000]25[/color]];
    sprintf(str, [color=bb0000]"[/color][color=907050]%d[/color][color=bb0000]"[/color], num);
    [/code]
    Cheers,
    Eric

Sign In or Register to comment.