A problem about strings
#5

That's not what I mean, and I'm asking for some ideas to solve the problem (or the reason that it act like this). My English is not very well, so sorry if any of you misunderstand this. I want to blank a string like the one in the code, but I can't do that by either x = "" or x[0] = '\0'. I have to loop through the entire string to clear it.
Let me explain the code again:
pawn Код:
new x[16];
x[0] = '1';
x[1] = '2';
x[2] = '3';
x[3] = '4';
x[4] = '5';
//Expected result of x: "12345", actual result: "12345"
printf("%d %s",strlen(x),x);
x = "";//It should clear the string, but it doesn't.
x[0] = '2';
x[1] = '3';
x[2] = '4';
//Expected result of x: "234", actual result: "23445"
//x[3] is still '4', as set in the above code.
//x[4] is still '5', as set in the above code.
printf("%d %s",strlen(x),x);
x[0] = '\0';//It should clear the string, but it doesn't.
x[0] = '5';
x[1] = '6';
//Expected result of x: "56", actual result: "56445"
//x[2] is still '4', as set in the above code.
//x[3] is still '4', as set in the above code.
//x[4] is still '5', as set in the above code.
printf("%d %s",strlen(x),x);
for(new i = 0;i < sizeof(x);i++) x[i] = '\0';//The string is cleared
x[0] = '9';
//Expected result of x: "9", actual result: "9"
//x[1] to x[4] are all cleared, so it works fine.
printf("%d %s",strlen(x),x);
I don't mean to shorten the string, or I'll be using strdel (it also doesn't work in this case). I use cell operations to the string because I want to copy a part of a string to a temp string, but I finally find it unable to remove the text/data in that temp string. I know I can use strmid or something, but whatever.
Sorry for my bad explanation, I hope you can understand this time.
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: 8 Guest(s)