samedi 28 mars 2015

Function to return a pointer to the largest number in an array



as you can tell by the title I need to write a function that returns a pointer to the largest number in an array, the functions gets a pointer to a double array and it's size. In addition I need to write a main function that will use this function. Here is the code that I wrote:



#include <stdio.h>
#include <stdlib.h>
void BigEl(double* arr, double arrSize);

void BigEl(double* arr, double arrSize)
{
int i;
double maximum, *x;
maximum = arr[0];
for (i = 1; i < arrSize; i++)
{
if (arr[i]>maximum)
{
maximum = arr[i];
}
}
*x = maximum;
}
void main()
{
double myarr[10];
int i;
printf("Please insert 10 numbers to the array\n");
for (i = 0; i < 10; i++)
{
scanf("%d", &myarr[i]);
}
BigEl(myarr, 10);


}


I get this error:



Error 1 error C4700: uninitialized local variable 'x' used


I don't understand what I did wrong because I did initialized x. Any kind of help is appreciated, in addition, tell me if the idea of my code was right because Im not sure if I understood the question correctly.




Aucun commentaire:

Enregistrer un commentaire