View Full Version : Converting Integers
t3jem
03-25-2005, 12:51 PM
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();
}
ZbuffeR
03-25-2005, 02:36 PM
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);
t3jem
03-25-2005, 05:04 PM
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? :confused:
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.
t3jem
03-26-2005, 06:57 AM
Works Great now Thanks very much
t3jem
03-26-2005, 08:19 AM
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?
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/documentation/C/CStdLib.html
http://www.uow.edu.au/~nabg/ABC/ABC.html
Hope that helps you.
t3jem
03-26-2005, 09:42 AM
thanks that helped. sorry about posting c in an ogl forum I needed some help and this forum was already up in my browser
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.