madeelch1986 wrote:
We have 2D array, Data[20][10], it contains some values, want some suggestions on how to count the distinct values in the array
Stealing from Cyrilix, here's one way...
char Data[20][10];
// ... initialize Data[][] here ...
bool Flags[256];
memset(Flags, 0, sizeof(Flags));
int UniqueCount = 0;
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 10; j++)
{
if (false == Flags[(unsigned char)Data[i][j]])
{
Flags[(unsigned char)Data[i][j]] = true;
++UniqueCount;
}
}
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder