MAMEWorld >> Programming
Previous thread Previous  View all threads Index   Next thread Next   Flat Mode Flat  

Anonymous
Unregistered
Re: C coders, what method do you use to clear a character array?
11/19/08 11:59 AM


> > Do you blow away the address, nt caring about the data?
> >
> > Do you blow away the data in memory?
> >
> > Do you allocate and de allocate?
> >
> > my preference:
> >
> > for(int i = 0; i > sizeof(CharArray); i++){ CharArray = '/0';}
> >
> >
> > Posting in the 'bin as I'm expecting this thread to stray a bit...
>
>
> try memset()
>
> http://www.codecogs.com/reference/c/string.h/memset.php

the equivalent would be:

memset(CharArray, 0, sizeof(CharArray));

You can't deallocate/allocate arrays & sizeof only does what you want for arrays & not pointers. If CharArray was a pointer then sizeof(CharArray) would return the size of the pointer ( sizeof(*CharArray) would return the size of what the pointer points at ). To use pointers you might want to use calloc ( malloc doesn't guarantee that the memory will be cleared at all ) & then if you later wanted to clear it you need to keep the size that you allocated and pass that into memset instead.







Entire thread
Subject Posted by Posted on
* g*DELETED* *DELETED* italieAdministrator 11/10/08 02:49 AM
. * C coders, what method do you use to clear a character array? italieAdministrator  11/10/08 02:54 AM
. * Re: C coders, what method do you use to clear a character array? krick  11/10/08 05:44 AM
. * Re: C coders, what method do you use to clear a character array? Anonymous  11/19/08 11:59 AM
. * Re: C coders, what method do you use to clear a character array? Mario Figueiredo  11/23/08 04:19 AM
. * Re: C coders, what method do you use to clear a character array? Anonymous  12/30/08 12:10 PM

Extra information Permissions
Moderator:  Pi 
0 registered and 114 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 3639