Re: A89: Clearing a string


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

Re: A89: Clearing a string




Or if we're going REALLY trying to shorten that code...

while(*str) *str++=0;

:-)

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

<< 
That will not work.  change "/0"  to '\0' and " "  to ' ' and it will work.  but
it looks ugly.  your code clears it with spaces too, but that works ofcourse,
but I like too clear with 0.

I think this line looks nicer:

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

if you want to clear to space, change the last zero to ' ' instead.

//Olle

JHill8075@aol.com wrote:
> 
> using this method, I'm assuming you don't know the length of the string, and
> that you want it filled with spaces.
> 
> num=0;
> while(string[num]!="/0")
> string[num++]=" ";
> 
> > What's the best way to clear a string in C.  I have tried several attempts
> >  and failed.  Any help will be appreciated.

 >>





Follow-Ups: