PDA

View Full Version : Pointer error need help error C2440: '=' : cannot convert from 'double' to 'double *'


tnecniv
Oct31-09, 12:57 PM
what is wrong with my code that i keep getting this error "error C2440: '=' : cannot convert from 'double' to 'double *'"

i am new to c and very weak in pointer.

#include<stdio.h>

//Function Prototypes//
int read(double pointco[][2]);
void obtainStatistics(double pointco[][2],int n,double *a);

//======================start of codes===========================//
void main(){
double pointco[100][2];
int i,j,n,p;
double temp[4]={0};


n=read(pointco);

for(p=0;p<5;p++){
printf("%lf %lf %lf \n",obtainStatistics(pointco,n,&temp[p])); //%lf %lf
}

for (i=0;i<n;i++){
for(j=0;j<2;j++){
printf("%lf",pointco[i][j]);
}//for j
printf("\n");
}//for i

}//main close

//======================End of main=============================//
int read(double pointco[][2]) {
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;

}//close read
//======================Read point.txt========================//
void obtainStatistics(double pointco[][2],int n,double *a)
{
int i,j,k;
double temp1,temp2;

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

a[0]+=pointco[i][j];
}
}//find sum of all x
for(i=0;i<n;i++){
for(j=1;j<2;j++){

a[1]+=pointco[i][j];
}
}//find sum of all y

for(i=0;i<n;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;
}

Hurkyl
Oct31-09, 01:11 PM
It would have helped if you indicated what line the error was at.

I notice the line
printf("%lf %lf %lf \n",obtainStatistics(pointco,n,&temp[p])); //%lf %lf
makes no sense....



But anyways, I didn't get the error you mentioned when I tried compiling your code....

But surely the error message is clear? You had an assignment, the right-hand side was of type double, and the left-hand side was of type double*.

Mark44
Oct31-09, 07:48 PM
I'm with Hurkyl on this. That printf line makes no sense. Your format control string indicates that printf should format three double numbers, but there is only one expression after the format string, not three. And besides that, obtainStatistics is a void function, so it doesn't return anything and you are attempting to evaluate it in the printf call.

Your error probably gives the file in which the error occurred and the line number. From that information you can find exactly where the problem is.