# Thread: Pointer error need help error C2440: '=' : cannot convert from 'double' to 'double *'

1. ## Pointer error need help error C2440: '=' : cannot convert from 'double' to 'double *'

Code:
```#include<stdio.h>
#include<math.h>

//Function Prototypes//
void obtainStatistics(double pointco[][2],int n,double a[]);
void trendLine(double temp[],int p, double m[]);
double closestPoint(double pointco[][2], int, double, double);
//======================start of codes===========================//
void main(){
double pointco[100][2];
int i,j,n;
double temp[4];
double m[2];
double *p;

obtainStatistics(pointco,n,temp);
trendLine(temp,n,m);

printf("------------------------------\n");
printf("Q1b.obtainStatistics");
printf("The sum of x^2: %lf \n",temp[0]);
printf("The sum of y^2: %lf \n",temp[1]);
printf("The sum of xy: %lf \n",temp[2]);
printf("The mean of x: %lf \n",temp[3]);
printf("The mean of y: %lf \n",temp[4]);
printf("------------------------------\n");

printf("Q1c.trendLine");
printf("m= %lf \n",m[0]);
printf("c= %lf \n",m[1]);
printf("Equation of regression line: y= %lfx+%lf \n",m[0],m[1]);
printf("------------------------------\n");
//=============================================================//
printf("Q2a Closest point");
p=closestPoint(pointco,n,m[0],m[1]);
printf("Closest point = (%lf, %lf)\n",*p,*(p+1));

//============================================================//
printf("Closest point = (%lf, %lf)\n",*p,*(p+1));
printf("------------------------------\n");
printf("Q1a.Statistics");
for (i=0;i<n;i++){
for(j=0;j<2;j++){
printf("%lf",pointco[i][j]);
}//for j
printf("\n");
}//for i
printf("------------------------------\n");

}//main close

//======================End of main=============================//
int i,j,n=0;

FILE *fp = fopen("points.txt", "r");

for(i=0;i<100;i++){
for(j=0;j<2;j++){
if(fscanf(fp,"%lf", &pointco[i][j] ) != EOF)
n++ ;
}//j
}//i
n=n/2;

fclose(fp);
return n;

void obtainStatistics(double pointco[][2],int z,double a[])
{
int i,j,k;
double temp1,temp2;
for(i=0;i<5;i++){
a[i]=0;
}
for(i=0;i<z;i++){
for(j=0;j<1;j++){

a[0]+=pointco[i][j]*pointco[i][j];
a[3]+=pointco[i][j];
}
}
a[3]=a[3]/z;
//find sum of all x^2

for(i=0;i<z;i++){
for(j=1;j<2;j++){

a[1]+=pointco[i][j]*pointco[i][j];
a[4]+=pointco[i][j];
}
}
a[4]=a[4]/z;
//find sum of all y^2

for(i=0;i<z;i++){
for(j=0;j<1;j++){
temp1=pointco[i][j];
for(k=1;k<2;k++){
temp2=pointco[i][k];
a[2]+=temp1*temp2;
}//k
}//j
}//i//find sum of x*y

return;
}

void trendLine(double temp[],int p,double m[]){
m[0]=0;
m[1]=0;

m[0]= (temp[2]-(p*(temp[3]*temp[4])))/(temp[0]-p*(temp[3]*temp[3]));//m
m[1]= temp[4]-temp[3]*m[0];//c
return;
}

double closestPoint(double pointco[][2], int q, double m, double c){
int i,j;
double distance;
double temp;
for(i=0;i<q;i++){
for(j=0;j<1;j++){
temp=pointco[i][j];
}
for(j=1;j<2;j++){
distance=(pointco[i][j]+m*temp+c)/(sqrt(pointco[i][j]*pointco[i][j]+temp*temp));
}
}
return distance;
}```
Why am i encountering the above error.. i am very weak in pointer. please advise

2. Look at the line that the error occurred - 'p' is a double*, but the function returns a double. See the conflict?

3. You need to indent the code.
Also, main returns int, not void.

4. Originally Posted by Sebastiani
Look at the line that the error occurred - 'p' is a double*, but the function returns a double. See the conflict?
what can i change to make this code run?
how do i use it to pass by reference the values from my closest point function to my main

```