itoa(bla,bla,bla); ???

This is a discussion on itoa(bla,bla,bla); ??? within the C++ Programming forums, part of the General Programming Boards category; lets say i have an int function that ,, big suprise outputs an integer, then i have a text output ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    3

    itoa(bla,bla,bla); ???

    lets say i have an int function that ,, big suprise outputs an integer, then i have a text output in opengl that can only output char * , i found out i can convert the int to a char by using the itoa(); function but can someone please tell me if i'm doing this right

    i get the integer from the function

    int fpsint(CalculateFrameRate());

    then i declare the char i want to store it in!

    char *fps;

    then i run itoa

    itoa(fpsint,fps, 10);


    should this not output fpsint to the char fps?

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    int fpsint = CalculateFrameRate();
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Re: itoa(bla,bla,bla); ???

    Originally posted by PaloDeQueso
    then i declare the char i want to store it in!

    char *fps;
    I hope you've allocated memory for the char* also, which you haven't shown here.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    3

    how do i allocate it

    do i do it like this fps=whatever[20];
    and the int thing, i always thought it could be done that ways because it's like doing everything in one step, i was always tought to assign at least zero the the var from the start but thank you

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    you need something like
    char fpsbuff[12] = "";
    itoa(fps,fpsbuff,10);

    the ="" is somewhat pointless, and I probably wouldn't do it in a fps calc where timing is so critical, but if you want to have an initial value, there ya go.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21