A problem about strings
#1

Hi, I found that if I do cell operations on strings, they cannot be cleared unless you loop through the string and clear cell-by-cell.
pawn Код:
new x[16];
x[0] = '1';
x[1] = '2';
x[2] = '3';
x[3] = '4';
x[4] = '5';
printf("%d %s",strlen(x),x);
x = "";
x[0] = '2';
x[1] = '3';
x[2] = '4';
printf("%d %s",strlen(x),x);
x[0] = '\0';
x[0] = '5';
x[1] = '6';
printf("%d %s",strlen(x),x);
for(new i = 0;i < sizeof(x);i++) x[i] = '\0';
x[0] = '9';
printf("%d %s",strlen(x),x);
Output:
Код:
5 12345
5 23445
5 56445
1 9
As you can see, neither x = "" and x[0] = '\0' can clear the string. It is reasonable for the latter to be unable to do so because it only clear the first cell to fake functions like strlen to think it is cleared, but x = "" should work.

So what's the problem with deleting the string?
Reply


Messages In This Thread
A problem about strings - by leong124 - 07.12.2011, 13:34
Re: A problem about strings - by TheArcher - 07.12.2011, 13:36
Re: A problem about strings - by leong124 - 07.12.2011, 13:39
Re: A problem about strings - by TheArcher - 07.12.2011, 13:41
Re: A problem about strings - by leong124 - 07.12.2011, 14:10
Re: A problem about strings - by JamesC - 07.12.2011, 14:19
Re: A problem about strings - by leong124 - 07.12.2011, 14:24
Re: A problem about strings - by cessil - 07.12.2011, 14:54
Re: A problem about strings - by cod4esle - 07.12.2011, 14:55
Re: A problem about strings - by leong124 - 07.12.2011, 15:49

Forum Jump:


Users browsing this thread: 5 Guest(s)