String Length (One Less)
#1

I've got no idea whats going on. for some reason the string is returning one less character than it should, I've got multiple 'stocks' that basically do the same thing for other things.


pawn Код:
stock RandomEx(min, max) // Used for getting RANDOM letters or numbers (using %c)
{
    return random(max - min) + min;
}

stock RandomString()
{
    new string[10];
    format(string, sizeof(string), "%c%c%c%c%c%c%c%c%c%c", RandomEx('A','Z'),RandomEx('A','Z'),RandomEx('A','Z'),RandomEx('A','Z'),RandomEx('A','Z'),RandomEx('A','Z'),RandomEx('A','Z'),RandomEx('A','Z'),RandomEx('A','Z'),RandomEx('A','Z'),RandomEx('A','Z'));
    return string; // returns 9 characters not 10.
}
Reply
#2

Try chaning new string[10] to string[11] and see if it still does it.
Reply
#3

I have come across this issue recently. I'm not sure why it happens, but I suppose PAWN keeps the last 2 slots for his null character ("\0").

EDIT: Yes, increasing the array size by 1 will fix the problem.
Reply
#4

Quote:
Originally Posted by Lynn
Посмотреть сообщение
Try chaning new string[10] to string[11] and see if it still does it.
I've already used that as a solution, but what I'm confused about is the fact that it's only this one (I need to check into it but I did recently change -d3 to -v in the pawn.cfg)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)