accessing "char * array" elements

how can char array elements be accessed?

I have this code but I'm not sure were my mistake is on.

1
2
3
4
for (int letter = 0;letter != strlen(s);letter++)
	{
		qva_Fonts[(int)*s]-> draw();
s++;// its meant to access the next element but it doesn't work 
You don't give enough information to tell why s++ doesn't work. Anyway, try
qva_Fonts[ s[letter] ]-> draw();
"s*" is a character array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
void CFonts::DrawText(char *s, GLfloat gfText_PosX, GLfloat gfText_PosY, GLfloat gfFont_Size, GLfloat gfFont_Spacing)
{ 
		 const int ki_end = strlen(s); 
	//for loop drawing each letter
	for (int letter = 0;letter != ki_end ;letter++)
	{
	
	//draw font in array
		qva_Fonts[(int)*s]-> draw();
s++;
		
	
	//loadmatrix Position & Scalling

		gfaaSca[0] = gfFont_Size;
		    gfaaSca[5] = gfFont_Size;
		        gfaaSca[10] = gfFont_Size;
		             gfaaSca[15] = gfFont_Size;

		gfText_PosX += gfFont_Spacing;
	    gfaaPos[12] = gfText_PosX;
		gfaaPos[13] = gfText_PosY;

	//multiply matrix
    
		glMultMatrixf(gfaaSca); 
		glMultMatrixf(gfaaPos);
		glLoadMatrixf(gfaaSca); glLoadMatrixf(gfaaPos);		
	}

	glLoadIdentity();
}
Last edited on
So...? Does it still not work?
By the way, you don't have to use strlen. If you're not going to use 'letter' for anything, you may write for(;*s != 0; s++){ ... }.
So... Did it work for you? We are trying to help but most of us will NOT compile some random code we find on this site so you'll have to tell us if this did the trick. Also you haven't stated a goal yet so I'm not sure that we're even headed in the right direction with this code.
Last edited on
success guys it worked

"*s" accesses an element

"s++" shifts to the next letter

Anyway I was plagued by the two many errors which caused me to get lost
Topic archived. No new replies allowed.