Need help with a loop
#1

I am trying to make a loop that will make and array hold a list of all of the different vehicle ids but for some reason it only stores the ids 400-610 and the loop never ends, i have tried to fix it but i can't see what i am doing wrong. could someone please tell me what the problem is?
here is the code for the loop:
Код:
        new vehids[211];
	new idx=0;
	for(new x=400;x<612;x++)
	{
	    vehids[idx]=x;
	    printf("x val is now %d",x);
	    idx++;
	}
	printf("Loop is done");
Reply
#2

Your array goes out of bounds, you declare an array of 200 bytes but you set the x to be "vehid[400+]".
Reply
#3

oops. I am so used to my eclipse ide for java which tells me when my array isn't big enough. thanks for the help man.
Reply
#4

Quote:
Originally Posted by saker277
Посмотреть сообщение
oops. I am so used to my eclipse ide for java which tells me when my array isn't big enough. thanks for the help man.
Sorry I was wrong, your array needs to be atleast 612 large, your IDs will then start from array[400] to array[611]. My bad.
Reply
#5

Should this work:
pawn Код:
new vehids[212];
for(new x = 0;x < 212;x++)
{
    vehids[x] = 400 + x;
    printf("x val is now %d",400 + x);
}
print("Loop is done");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)