Skip to main content
gamedev.net
🔒 Locked

Problem With Reading Char*

Started by jtmerchant Oct 31, 2004 at 10:10 AM 1 replies 400+ views
Original Post
jtmerchant
jtmerchant
while(title != '!')  {
			while(title != '~')  {
				string[j]=title;
				j++;
				i++;
			}
			int left=rect.left;
			for(i=0;i<numCol;i++)  {
				left+=cellwidth[numCol];
			}
			RECT rect2=CreateRect(left,rect.top,left+cellwidth[numCol],rect.top+40);
			UIFont->DrawText(UISprite,string,j,&rect2,
							DT_LEFT | DT_NOCLIP,0xFFFFFFFF);
			i++;
			j=0;
			numCol++;
		}


For some reason, this loop executes 6 times when it should only do it once. The string title is equal to "Hello~!". What it should do is print out "Hello", but it prints out "Hello" then in the next column "ello", then "llo", "lo", "o", "". For some reason, i, at the beginning of the first while loop is 0, 1, 2, 3, 4, 5, then 0 the next time the function is called. After the second while loop i is always 5. It is the same even if I take out i++; at the bottom of the outer loop. I've been trying to figure this out for days. Any ideas?
RLigon
RLigon
Looks like your problem is here:

for(i=0;i<numCol;i++)


You're using 'i' as a loop iterator, when you are already using it to traverse your character array.
jtmerchant
jtmerchant
Wow. Thanks. Its always something like that, heh...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.