So I'm have trouble with my code , and cannot figure out why...I thought the possibilty of the fact that changing from double to int might change the function since it works fine with integers.

Code:

```
void
do_catavg(csv_t *D, int cat, int col) {
int i,j,k;
int count=0,nvalues[MAXROWS];
double category[MAXROWS],category_red[MAXROWS];
double average[MAXROWS];
double sum;
printf("%s %s\n",D->labs[cat-1],D->labs[col-1]);
for(i=0;i<D->nrows;i++){
category[i]=D->vals[i][cat-1];
printf("%f ",category[i]);
}
printf("\n");
sort_int_array(category,D->nrows);
printf("\n");
distinct(category,category_red,D->nrows);
printf("%d\n",distinct(category,category_red,D->nrows));
for(i=0;i<distinct(category,category_red,D->nrows);i++){
for(j=0;j<D->nrows;j++){
sum=0;
count=0;
if(category_red[i]==category[j]){
sum+=D->vals[j][col-1];
count++;
}
average[i]=sum/count;
nvalues[i]=count;
}
printf("%f %d\n",average[i],nvalues[i]);
}
return;
}
```

Functions:

```
void
sort_int_array(double A[], int n) {
int i, j;
/* assume that A[0] to A[n-1] have valid values */
for (i=1; i<n; i++) {
/* swap A[i] left into correct position */
for (j=i-1; j>=0 && A[j+1]<A[j]; j--) {
/* not there yet */
int_swap(&A[j], &A[j+1]);
}
printf("%f ",A[i]);
}
printf("--BReak--");
printf("The first value is %f ",A[0]);
/* and that's all there is to it! */
}
int distinct(double A[],double B[], int n){
int i;
int new=0;
for(i=0;i<n;i++){
if(A[i]!=A[i+1]){
B[new]=A[i+1];
new++;
printf("%f ",B[i]);
}
}
return new;
}
/* exchange the values of the two variables indicated
by the arguments */
void
int_swap(double *p1, double *p2) {
double tmp;
tmp = *p1;
*p1 = *p2;
*p2 = tmp;
}
```

Output:

```
location mintemp
18.000000 22.000000 18.000000 22.000000 18.000000 22.000000 18.000000 22.000000
18.000000 22.000000
18.000000 18.000000 18.000000 18.000000 18.000000 18.000000 18.000000 18.000000
18.000000 --BReak--The first value is 22.000000
0.000000 0.000000 0.000000 0.000000 2
0.000000 0.000000 14.200000 1
0.000000 0.000000 -1.#IND00 0
0.000000 0.000000 > k 5 6
```

Please do not care about *distinct* function because it is broken at the moment. But I don't understand why the sorting array doesnt work...

PS I have full confidence that the rest of the code is fine and works, except until the sorting array.

Thank You!