Problems making a sine scroller, converting char to const char*
category: code [glöplog]
So, i am trying to make a Sine scroller, and i am having problems with it.
As you can see i am trying to obtain each letter from a "char" array (frase[]) and convert each letter to a "const char*" value so i can use the "Font:print" function, but i am having problems in this conversion, how to? :/
Trolls: Sorry for being such an idiot with this stupid question, nobody born knowing.
Code:
char frase[] = "Sine Scroller";
float ls = 1.0f;
int len = strlen(frase);
for (int i=0;i < len;i++)
{
glPushMatrix();
glTranslatef(-len*ls/2.0f + ls*i,0.0f,5.0f + sin((i*10 + t*4)DEG));
glRotatef(90.0f,1.0f,0.0f,0.0f);
GLfloat scale = 2.0f;
glScalef(scale,scale,scale);
Font::print((const char*)frase[i]); // Receives a const char* value. // Error goes here.
glPopMatrix();
}
As you can see i am trying to obtain each letter from a "char" array (frase[]) and convert each letter to a "const char*" value so i can use the "Font:print" function, but i am having problems in this conversion, how to? :/
Trolls: Sorry for being such an idiot with this stupid question, nobody born knowing.
Wrong category, thats what happens when you are 3 days solving this problem and all you want it's the answer... oh well...
Quote:
Wrong category
That's why gloperators are here :)
I presume Font::print() takes a const char*, meaning a string and that there is no single-character equivalent.
In that case you need to extract each character into its own string like so:
In that case you need to extract each character into its own string like so:
Code:
for (int i=0;i < len;i++)
{
char str[2] = "";
str[0] = frase[i]; //str[1] == 0
glPushMatrix();
glTranslatef(-len*ls/2.0f + ls*i,0.0f,5.0f + sin((i*10 + t*4)DEG));
glRotatef(90.0f,1.0f,0.0f,0.0f);
GLfloat scale = 2.0f;
glScalef(scale,scale,scale);
Font::print(str);
glPopMatrix();
}
The real problem is that frase itself is of type (char*), and frase[i] is of type (char). You were trying to cast a (char) to (const char*), which doesn't make sense. So, what Tjoppen said.
Tjoppen : Are you some kind of programming Magician? It worked! Many thanks!
This line
Could it not read:
Code:
Font::print((const char*)frase[i]); // Receives a const char* value. //
Could it not read:
Code:
Font::print(&frase[i]); // Receives a const char* value. //
4Tey: Nope, because as it seems the Font::print function is for printing strings, not individual characters. What would happen is that instead of just the one character you'd always get the part of the whole string that starts with that character. Interesting effect also but probably not what Blacksheep needed ;D
Ah, yes I see kb_ :)
I would probably make a Font::printchar(char ch) little function :)
I would probably make a Font::printchar(char ch) little function :)
Quote:
Trolls: Sorry for being such an idiot with this stupid question, nobody born knowing.
no question is idiotic. you have to start somewhere.
wasnt there a .c_str() method aswell to convert std strings to const chars? been a while since i messed with that can of ugly worms. guess its also possible he might not be wanting to use std
well, c_str() sure won't help with converting a single character of a string to a new string, either...
...and it's STL, not STD :)