The following code find the max and min value in table.
For the max value (not for the min) , i need also its position.
The compilation is succeded.
I want know if the functional of the code is also correct or if there is an other easy methode.
#define MAX_VALUE 0
#define MIN_VALUE 1
typedef Min_Max_Data
{
unsigned char Value;
unsigned char Position;
}Min_Max_Data_t;
Min_Max_Data_t Data;
void Min_Max_Data_Value(unsigned char *Array
, unsigned char Min_Max
, unsigned char Dim)
{
unsigned char i;
switch (Min_Max)
{
case MAX_VALUE:
{
Data.Value = *Array;
Data.Position = 0;
for (i = 0; i < Dim; i++)
{
if (*(Array + i) > Data.Value)
{
Data.Value = *(Array + i);
Data.Position = i;
}
}
break;
}
case MIN_VALUE:
{
Data.Value = *Array;
Data.Position = 0;
for (i = 0; i < Dim; i++)
{
if (*(Array + i) < Data.Value)
{
Data.Value = *(Array + i);
}
}
break;
}
default:
break;
}
}