Thread: what is wrong?

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    21

    what is wrong?

    i have written the code below:
    Code:
    #include<stdio.h>
    void copy1(float a[],float b[],int c);
    void copy2(float *d,float *c,int a);
    int main(void)
    {
        int a;
        float *b;
        static float rain[12]=
        {10.2,8.1,6.8,4.2,1.5,2.6,2.6,6.4,5.8,4.5,1.1,5.9};
        static float copy1[12]=
        {0,0,0,0,0,0,0,0,0,0,0,0};
        static float copy2[12]=
         {0,0,0,0,0,0,0,0,0,0,0,0};
       copy1(rain,copy1,6);
       copy2(rain,copy2,5);
       b=copy1;
       for (a=0;a<12;a++)
       
         printf("%4.1f",*(b+a));   
       
       
        system("pause");
        return 0;
    }
    void copy1(float a[],float b[],int c)
    {
         int d;
         for (d=0;d<c;d++)
           b[d]=a[d];
         
    }
    void copy2(float *d,float *c,int a)
    {
         int b;
         for (b=0;b<a;b++)
          (c+b)=*(d+b);
    }
    but after i have compiled it, I got the error saying "the called object is not a function" for copy1 and copy2, and "invalid value in assignment" for the last statement (c+b)=*(d+b); why is it so?

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Australia - Melbourne
    Posts
    63
    this has already been answered go to link below
    http://cboard.cprogramming.com/showthread.php?t=87167

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You have a function named copy1() and an array named copy1 that is local to main(). In your code, the compiler can't necessarily work out what you intend. Rename one of them. Similarly for copy2.

    Within your copy2() function, the expression (c+b) is a pointer to float (the address of the b'th element of array c), and *(d+b) is a float (the value of the b'th element of array d). It is not possible to assign one directly to the other as they are different types. You probably intended "*(c+b)=*(d+b)"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM