Here is my code, cant figure out why the size of array is 2. Help me out in correcting my code, so that i can get the Max() function right.
//Max() gets the max value and Min()gets min value
#include <stdio.h>
#include "conio.h"
struct test {
int input[10];//input array , I need to get out Max and min functions right
int min;
int max;
} testDB[2] =
{
{{1,2,3,4,5,6},1,6},
{{3,4,5},3,5},
};
int Max(int* input){
int max,i,size;
max = input[0];
size = sizeof(input)/sizeof(input[0]);
printf("\n-----------\n");//print debugging
printf("\t%d",size);
printf("\n-----------\n");//print debugging
for(i=0;i<size;i++)
{
if(max<input[i])
max = input[i];
printf("%d\n",max);
}
return max;
}
int Min(int*input)
{
int min,i;
min = input[0];
for(i=0;i<sizeof(input)/sizeof(input[0]);i++)
{
if(min>input[i])
min = input[i];
}
return min;
}
void testCases()
{
int max,min,i;
for(i=0; i<2; i++) {
printf("Test cases for Max\n");
max = Max(testDB[i].input);
if((testDB[i].max==max)) printf("PASSED\n"); else printf("FAILED\n");
printf("TestCases for Min\n");
min = Min(testDB[i].input);
if((testDB[i].min==min)) printf("PASSED\n"); else printf("FAILED\n");
}
}
int main()
{
testCases();
return 0;
}
This is probably it , But as a newbie I am not able to figure this thing