Below is my code. The problem I am having is that when trying to print out a value in the main function from a pointer in a function its giving me wacky values. Like for example my maximum value lets say should be 90, instead its giving me 16, for minimum should be 19 but its giving me 3098789, and for gtr its giving me 16 again when it should be 1. All my logic should be correct its just the way my pointers are i believe is what is giving me the problem and thats where i am stuck.

Code:Program Purpose: To find the max and min in a function and to find the average and number greater than average in another function from an input file.*/ #include<stdio.h> #include<math.h> double average(int x[], int npts, int *gtr); void ranges(int x[], int npts, int *max_ptr, int *min_ptr); int main(void) { /*Intialize Variables*/ int k=0; int npts; int x[20]; FILE *inp; double ave; int *max_ptr; int *min_ptr; int *gtr; int num; /*Open File and read data into array.*/ inp=fopen("input7.dat","r"); if(inp==NULL) printf("Error opening input file. \n"); else { fscanf(inp, "%d", &npts); for (k=0; k<npts; k++) fscanf(inp, "%d", &x[k]); } ranges(x, npts, max_ptr, min_ptr); printf("Maximum is %d and minimum is %d \n", max_ptr, min_ptr); ave = average(x, npts, gtr); printf("Average is: %lf \n", ave); printf("Number of values in array that are greater than average: %d \n", gtr); return 0; } /*----------------------------------------- This function determines max and min values from one dimensional array.*/ void ranges(int x[], int npts, int *max_ptr, int *min_ptr) { /*Declare Variables*/ int k; int max_x; int min_x; /*Determine maximum value in the array*/ max_x = x[0]; for (k=1; k<=npts-1; k++){ if(x[k]>max_x) max_x=x[k];} max_ptr = max_x; /*Determine minimum value in the array*/ min_x = x[0]; for (k=1; k<=npts-1; k++) if(x[k]<min_x) min_x=x[k]; min_ptr=min_x; return; } /*-------------------------------------------------- This function returns the average value and determines the occuarance of numbers greater than average.*/ double average(int x[], int npts, int *gtr) { /*Declare Variables*/ int k; double sum=0; double ave_x; /*Compute*/ for (k=0; k<=npts-1; k++) sum+=x[k]; ave_x = sum/npts; gtr = 0; for (k=0; k<=npts-1; k++) if(x[k] > ave_x) gtr++; /*Return mean*/ return ave_x; }