Link to home
Start Free TrialLog in
Avatar of shav
shav

asked on

reset an array

Hi,
   think this is a stpuid question but how do reset an arry. I've declared an array

char buffer[10000]={0};

and through out my program I add to it using strcat. Now at some point I want to empty the array and start again by using strcat to add contents to it. I've tried
temp_buffer[]={0};    and also
temp_buffer={0};

I don't want to use a for loop and reset each character since the array is so big, for loop might use up resources? Thanks
Shav
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi shav,

Actually, a for() loop will be faster than you think.

It's only a couple of machine instructions long.  And how do you think memset works?  :)

register idx;
for (idx = 0; idx < 10000; idx++)
  buffer[idx] = 0;


Some machines do have a memory initialization instruction, but I don't think that Intel is one of them.

Good Luck!
Kent
Avatar of shav
shav

ASKER

Simple when you know how!