centering text

I have a game that I want to be able to center text in. The only problem is that the way I thought would work just makes my game stop responding. I don’t know of any other way to center it efficiently without having to count the characters in each string. here is my code hopefully you can figure it out.

void renderBitmapString(float x,float y,float z,char *string, int center) {
char *c;
char *b;
int amount=0;
if(center == 1)
glRasterPos3f(x-amount/2, y,z);
glRasterPos3f(x, y,z);
for (c=string; *c != ‘\0’; c++) {
glutBitmapCharacter(GLUT_BITMAP_9_BY_15, *c);

The algorithm for centering is correct, but you forgot a * in your first for loop…

for(b = string; *b!=’\0’; b++)

Alternatively, you could just use the standard c function strlen:
amount = strlen(string);

Thanks alot! now it works great! :slight_smile: