Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Oct 31, 2009 #1
    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[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[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[j];
    }
    }//find sum of all x
    for(i=0;i<n;i++){
    for(j=1;j<2;j++){

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

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


    return;
    }
     
  2. jcsd
  3. Oct 31, 2009 #2

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Re: Pointer error need help error C2440: '=' : cannot convert from 'double' to 'doubl

    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*.
     
  4. Oct 31, 2009 #3

    Mark44

    Staff: Mentor

    Re: Pointer error need help error C2440: '=' : cannot convert from 'double' to 'doubl

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Pointer error need help error C2440: '=' : cannot convert from 'double' to 'double *'
Loading...