Re: A89: Clearing a string


[Prev][Next][Index][Thread]

Re: A89: Clearing a string




I don't think yours will actually work though--it won't clear the first char.  Rather, use:

for(int i=0; str[i]; str[i++]=0);

If you post-increment i in the conditional, it will test before the first loop and thus skip str[0] in the clearing code.  Incrementing in the "increment" piece of the for loop generally works better =P


In a message dated Mon, 3 Jul 2000  4:10:02 PM Eastern Daylight Time, Olle Hedman <oh@hem.passagen.se> writes:

<< 
just don't forget to save the stringpointer if you want to use the string
variable again :)

//Olle

ComAsYuAre@aol.com wrote:
> Or if we're going REALLY trying to shorten that code...
> 
> while(*str) *str++=0;
> 
> :-)

 >>





Follow-Ups: