Results 1 to 8 of 8

Thread: Converting Integers

  1. #1
    Senior Member Regular Contributor
    Join Date
    Mar 2005
    Posts
    115

    Converting Integers

    Hi,

    I know all my post are probably getting anoying but I need the info I won't have the net for 2 weeks after this sunday.

    Anyways I have a font function In my program that uses char *string variable. The program that I am using it for counts points that can go very high and in my other programs I would just use if statements to change the numbers to char. If I put an integer variable in my function it will give me an error saying it can't convert integer to char*. Does anybody have any Ideas?

    here is the code in case you need it.

    void renderBitmapString(float x,float y,float z,char *string) {
    char *c;
    glPushMatrix();
    glTranslatef(x, y,z);
    for (c=string; *c != '\0'; c++) {
    glutStrokeCharacter(GLUT_STROKE_ROMAN, *c);
    }
    glPopMatrix();
    }

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Converting Integers

    Standard command sprintf should allow this :
    char myString[50] ;
    sprintf(myString,"myInteger as the following value: %d",myInteger);
    then simply call your renderBitmapString(x,y,z,myString);

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2005
    Posts
    115

    Re: Converting Integers

    Ok I put it in my game but now when I run it I get an error when I get to the point of using it. I am probably using it wrong since i've only seen it a couple times and but never looked into it. Can you give me an example please?

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: Converting Integers

    Generally this is only an opengl forum. So I can advise you to look for a good general programming forum. They'll be more aimed for some of your questions.

    char my_str[64];
    int an_int_value = 10241024;
    sprintf (my_str,"an_int_value has %d as value", an_int_value);

    will put the string "an_int_value has 10241024 as value" inside my_str.

    Then you'll be able to write it with your glut command using my_str:

    char *c;
    for (c=my_str; *c != '\0'; c++)
    glutStrokeCharacter(GLUT_STROKE_ROMAN, *c);

    should work fine.

    Hope this helps.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Mar 2005
    Posts
    115

    Re: Converting Integers

    Works Great now Thanks very much

  6. #6
    Senior Member Regular Contributor
    Join Date
    Mar 2005
    Posts
    115

    Re: Converting Integers

    Ok now I have another problem when I try to convert a float into a char all I get is a zero. do I need to use something else for floats?

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: Converting Integers

    Originally posted by Terminatore3:
    Ok now I have another problem when I try to convert a float into a char all I get is a zero. do I need to use something else for floats?
    yes, some argument change. You REALLY should at least have a look at a C documentation. Just google it, you'll find many, several are good. Not all people react as me And you should understand them because this is an opengl forum not a C forum.

    for float, sprintf changes.
    sprintf (your_string,"blablabla %f", your_float);

    %d is for int
    %f for float
    %c for char
    %s for strings (char*)

    Now it will be well, and everyone will appreciate, that you do like a big boy. Just look for what you're seeking at the good places.

    Finally, here are two links I quicly found, you really should have a deeper look at them:

    http://www.infosys.utas.edu.au/info/...C/CStdLib.html

    http://www.uow.edu.au/~nabg/ABC/ABC.html

    Hope that helps you.

  8. #8
    Senior Member Regular Contributor
    Join Date
    Mar 2005
    Posts
    115

    Re: Converting Integers

    thanks that helped. sorry about posting c in an ogl forum I needed some help and this forum was already up in my browser

Similar Threads

  1. glColor4b with integers.
    By Registrar in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-12-2011, 02:23 PM
  2. Writing integers as text
    By Kaega in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-17-2010, 11:24 AM
  3. Vertex Arrays - Signed Integers?
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-13-2004, 02:18 PM
  4. output of integers
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 09-14-2002, 06:06 PM
  5. floats or integers
    By mms in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 03-29-2001, 08:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean