Im trying to debug why my helpers.c in the find pset is not working perfectly. I kept getting random large numbers in my array and I kept going up the ladder in the function to the point of initialising the array.
int max = 0;
for (int i = 0; i < n; i++)
{
if (values[i] > max)
{
max = values[i];
}
}
// Declare variables
int * count_arr = malloc(max);
for (int j = 0; j < n; j++)
{
printf("%d ", count_arr[j]);
}
printf("\n");
As you can see, I try to find the max value of the given array and then declare an empty array up to the maximum number in the array. The second for loop is just so I can debug the results which are 0 0 0 0 0 0 135137 0 0
when given int values[9] = {3,4,1,5,9,7,8,6,2}
as input. Can anyone please help me figure out why there is that random number there?