Page 1 of 1

Clearing a string (char array)

Posted: Tue Oct 30, 2007 5:19 pm
by piranha
Uh, is there a better way to clear a string then just:

Code: Select all

for(i=0;i<128;i++) str[i] = '\0';
Because it gets old typing that......-JL

Posted: Tue Oct 30, 2007 7:30 pm
by Colonel Kernel
memset?

Re: Clearing a string (char array)

Posted: Tue Oct 30, 2007 9:30 pm
by Brendan
Hi,
piranha wrote:Uh, is there a better way to clear a string then just:

Code: Select all

for(i=0;i<128;i++) str[i] = '\0';
Because it gets old typing that......-JL
Do you need to clear the string? Often, for ASCIIZ strings it's enough to do:

Code: Select all

str[0] = '\0';
Cheers,

Brendan

Posted: Wed Oct 31, 2007 5:29 am
by XCHG
I recommend using aligned buffers for 4 bytes in each iteration using any general purpose register (GPR) or using 8 bytes per iteration using MMX. Putting 1 byte per iteration is really not a good idea in my opinion.

Posted: Wed Oct 31, 2007 5:32 am
by Solar
Which means, memset. ;)

Posted: Wed Oct 31, 2007 5:01 pm
by piranha
Thanks, it did work with just str[0] = '\0'

Cool

-JL