Reputation: 3313
I would like to ask if there is any fast way(using memset for example) to clear a char table like
char mytable[2][10];
For example as I know using memset
memset(mytable, 0, sizeof(mytable));
is used for 1D tables.
Upvotes: 0
Views: 878
Reputation:
you can use pointer :
register int i ;
const int max = MAXROW * MAXCOL ;
char *p = &mat[0][0] ;
for (i=0; i < MAXROW * MAXCOL ; i++)
*p++ = 'x' ;
Upvotes: 0
Reputation: 70929
What you have written will work for 2-D table as well. Actually it will work for any dimension of the array(assuming you are memset-ing a static array)
Upvotes: 0
Reputation:
They're called arrays, not "tables".
And the very same code works for any array with arbitrary number of dimensions.
Upvotes: 5