Clear all values in a multidimensional array

September 13, 2011 at 12:59:15
Specs: Windows 7
hey guys, I want to clear all values in a 2 dimensional array. Here's the code:

char array[10][20];
//array has assigned a value throughout its 10 x 20 addresses available


will this work?

See More: Clear all values in a multidimensional array

Report •

September 13, 2011 at 13:55:48
Probably not; strlen() returns the distance from the first null character from the start. It's the effective size of the string, not the amount of memory reserved for the string. sizeof() is probably what you want:
memset(array, 0, sizeof(array));

But if you're just looking to declare and initialize your array to all nulls, the following will do, and will do it faster:
char array[10][20] = { 0 };

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question