int position_of_largest(int * array, int size)
{
int largest, i, largest_i;
i = 0;
largest_i = 0;
while (i < size)
{
if (i == 0)
{
largest = array[0];
largest_i = 0;
}
else
{
if (largest < array[i])
{
largest_i = i;
largest = array[i];
}
i++;
}
}
return largest_i;
}
This code is supposed to find the index of the highest element in the array and return it. There is a segmentation fault in this code, apparently, but I have no clue what it is! I have looked through the code many times and I don't see any problem. I am new to C, btw (which explains a lot). Thanks.