pouët.net

Go to bottom

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.

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 :)
added on the 2012-03-15 19:31:14 by Tomoya Tomoya
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:
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(); }
added on the 2012-03-15 19:31:21 by Tjoppen Tjoppen
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.
added on the 2012-03-15 19:34:07 by xTr1m xTr1m
Tjoppen : Are you some kind of programming Magician? It worked! Many thanks!
This line
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. //
added on the 2012-03-15 19:36:32 by 4Tey 4Tey
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
added on the 2012-03-15 19:48:31 by kb_ kb_
Ah, yes I see kb_ :)
I would probably make a Font::printchar(char ch) little function :)
added on the 2012-03-15 20:09:27 by 4Tey 4Tey
Quote:
Trolls: Sorry for being such an idiot with this stupid question, nobody born knowing.


no question is idiotic. you have to start somewhere.
added on the 2012-03-15 20:17:28 by rudi rudi
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
added on the 2012-03-16 02:01:59 by psenough psenough
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 :)
added on the 2012-03-16 14:34:06 by Gargaj Gargaj

login

Go to top