Re: A89: Clearing a string


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

Re: A89: Clearing a string




eck.. ollie's works fine

*(str++)=0;

that sets the value *str to 0, then increments str
while(*str) *(str++)=0;
while the value at str is not zero, set the value to zero and increment str



ComAsYuAre@aol.com wrote:
> 
> 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;
> >
> > :-)
> 
>  >>



References: