07.12.2011, 15:49
The problem is that the string isn't cleared completely. If you use x = "" or x[0] = '\0', only the first cell will be cleared, but you think it is completely empty. If you put a character to the first cell again, the entire string with the original characters stored will show up again, which is my problem.
Output:
Since it act like this, I am not sure if there is any characters after the NULL character that can cause such problems, I have to loop through the whole string and clear it cell-by-cell.
Anyway I can get the range of the string and copy it by things like strmid instead of copying cell-by-cell, but I want to know what the problem is.
Let's do the same thing with a nested loop (more suitable to my actual case):
Output:
The output explains it all.
pawn Код:
new x[16];
x[0] = '1';
x[1] = '2';
x[2] = '3';
x[3] = '4';
x[4] = '5';
x = "";
printf("%c %c %c %c %c",x[0],x[1],x[2],x[3],x[4]);
x[0] = '2';
printf("%c %c %c %c %c",x[0],x[1],x[2],x[3],x[4]);
x[1] = '3';
printf("%c %c %c %c %c",x[0],x[1],x[2],x[3],x[4]);
x[2] = '4';
printf("%c %c %c %c %c",x[0],x[1],x[2],x[3],x[4]);
Код:
(yes it is empty here, making you to think that it is completely cleared.) 2 2 3 4 5 (The problem occurs here, the last 4 cells shouldn't appear, as they should have been removed already) 2 3 3 4 5 2 3 4 4 5
Anyway I can get the range of the string and copy it by things like strmid instead of copying cell-by-cell, but I want to know what the problem is.
Quote:
kinda made up a scenario in my head about a dynamic string based on some variables, personally I'd just use another string but I came up with this script if I had to use the same string.
pawn Код:
0101010101 23232 not sure if it'd be faster than making all the cells null |
pawn Код:
new x[16];
for(new j = 1;j < 3;j++)
{
x[0] = '\0';
for(new i;i<(10 / j);i++)
{
switch(i)
{
case 1, 3, 5, 7, 9: x[i] = 49 + (j - 1) * 2;//'1' if j = 1, '3' if j = 2
default: x[i] = 48 + (j - 1) * 2;//'0' if j = 1, '2' if j = 2
}
}
print(x);
}
Код:
0101010101 2323210101