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
C

Avatar of undefined
Last Comment
shav

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
sunnycoder

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Kent Olsen

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
shav

ASKER
Simple when you know how!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck