Reputation: 83
I need to clear 2 arrays before i execute a function a 2nd time.
They are initially setup globally as :-
NSString *allAnswers[10];
int used[6];
What would be needed to clear/reset these before running the function again?
Thanks.
Upvotes: 0
Views: 96
Reputation: 437442
You can loop through those items, resetting their values to whatever you want.
for (NSInteger i = 0; i < 10; i++)
allAnswers[i] = nil;
for (NSInteger i = 0; i < 6; i++)
used[i] = 0;
If using Objective-C, you might want to consider using NSMutableArray
in the future rather than C-language arrays like these.
Upvotes: 2
Reputation: 366
memset(allAnswers, 0, sizeof(NSString*)*10);//This statement to clear array of NSString pointers
memset(used, 0, sizeof(int)*6);//This statement to clear array of integers.
Alternatively you can run loop to clear each element individually.
Upvotes: 0
Reputation: 106012
Use a loop to clear your arrays by 0
or whatever value you want.
for(int i = 0; i < 10; i++)
{
if(i < 6)
used[i] = 0;
allAnswer[i] = 0;
}
Upvotes: 0