Thread: Called Object type is not a function or function pointer (probably beginner mistake)

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    7

    Called Object type is not a function or function pointer (probably beginner mistake)

    Hey guys, I've just started coding C about a week ago and I'm getting an error in two lines of code one saying "Called object type 'int' is not a function or function browser" and "Called object type 'int' is not a function or function browser". I'd like to know why that's happening in my program but also what that means in general. Another one that isn't actually failing the build is "Conversion specifies build type 'double' but the argument has type 'double *', and I was wondering what that means. All the errors are in the "a series" function. The point of the code in this section is to loop a certain number of times, (entered by the user(n)) adding a function during each iteration of the loop, with a time input (t). Thanks for the help. Here's the code
    Code:
    #include <stdio.h>
    #include <time.h>
    #include <math.h>
    #define pi 3.141593
    
    
    int aseries();
    int bseries();
    int cseries();
    
    
    int main()
    {
    //Beginning program stuff
    
        
    //Defining variables to find the time
        time_t now;
        time(&now);
        printf("%s\n", ctime(&now));
    printf("--------------------------------------------------------------\n");
        
    //Main Program
        char choice;
    printf("What type of evaluation would you like to perform?\n\t1.)Calculate voltage for a given value of time.\n\t2.)Input t and epsilon.\n\t3.)Find the change in voltage between t2 and t1.\nEnter '1' for choice one, '2' for choice two, or '3' for choice three: ");
        scanf("%d",&choice);
        
        if (choice == 1){
            aseries();
        }
    
    
        if (choice == 2){
            bseries();
        }
        
        if (choice == 3){
            cseries();
        }
        
        
        
        return 0;
    }
    
    
    int aseries()
    {
        
        double t;
        int n;
        double total=0;
        double v;
    
    
        
        
    //Prompting the user for time input
    printf("Enter the time you would like to evaluate the voltage at: ");
        scanf("%lf",&t);
        
    //Prompting the user for number of terms in the series
    printf("Enter the number of terms in the series you would like: ");
        scanf("%lf",&n);
        
    //Building the series
        
        for (int i=0;i<=n;i++){
          total = total + ((1/((2(i)-1)^2))*cos(((2(i)-1)*pi*t)/3)) //This is where the "Called object type 'int'..." error is 
            
        }
        
        v=(3/2)-(12/pow(pi,2))(total); //This is where the "Called object type 'double'..." error is 
        
        printf("%lf",&v); //This is where the "Conversion specifics type..." error is 
        
        
        
        
        
        return 0 ;   
    
    
    }
    
    
    int bseries()
    {
        double t;
        double e;
        
    //Prompting the user for time input
    printf("Enter the time you would like to evaluate the voltage at: ");
        scanf("%lf",&t);
        
    //Prompting the user for epsilon input
    printf("Enter the epsilon value you would like to use: ");
        scanf("%lf",&e);
        
        
        
        return 0;
        
    
    
        
    }
    
    
    int cseries()
    {
        double t1;
        double t2;
        int n;
        
        
    //Prompt the user for time inputs
    printf("Enter the beginning of the time you would like to evaluate the voltage at: ");
        scanf("%lf",&t1);
    
    
    printf("Enter the end of the time you would like to evaluate the voltage at: ");
        scanf("%lf",&t2);
    
    
    //Prompting the user for number of terms in the series
    printf("Enter the number of terms in the series you would like: ");
        scanf("%lf",&n);
        
        return 0;
        
    }
    Last edited by Ethan_K; 03-18-2012 at 09:43 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Next time, try including line numbers for those errors. Why did you feel the need to go in and manually color everything?
    Code:
        int n;
    ...    
    printf("Enter the number of terms in the series you would like: ");
        scanf("%lf",&n);

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    7
    Quote Originally Posted by quzah View Post
    Next time, try including line numbers for those errors. Why did you feel the need to go in and manually color everything?
    Code:
        int n;
    ...    
    printf("Enter the number of terms in the series you would like: ");
        scanf("%lf",&n);

    Quzah.
    The code was already colored from Xcode. And I changed the %lf to a %d, but it didn't fix any of the errors.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
     total = total + ((1/((2(i)-1)^2))
    All of that is integer math. ^ is not power of, it's XOR. I don't know what you think 2(i) does, but it doesn't do what you think it does.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Ethan_K View Post
    The code was already colored from Xcode.
    If you set whatever in Xcode so that it exports plain text instead, the forum will highlight and add line numbers. Then you can include the line number of the errors. That is a little simpler and more obvious than adding comments to the same effect.

    Lose the address of operator & here:

    Code:
        printf("%lf",&v);
    The "called object..." errors are because you need to add some multiplication signs, *. You can't use "2(3+1)", you have to use "2*(3+1)".

    Beware what quzah said about ^ not being the operator you may think it is.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Mar 2012
    Posts
    7
    Alright yeah thanks, I'm still adjusting to syntax differences between this and matlab. I switched out the ^ for the pow function. And after I removed the & everything appears to be working correctly, so thanks guys! And just to clear things up, the & just points to a variable, right? So for most things I don't need a pointer, besides scanf()?

  7. #7
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Here is a better definition of PI (and note that manifest constants are conventionally spelled in uppercase). Put this after your includes at the top of the program. (The ifndef is just in case math.h has already defined it.)
    Code:
    #ifndef M_PI
    #define M_PI 3.1415926535897932385
    #endif
    
    #define PI_SQUARED (M_PI * M_PI)
    Note that because of the way integer division works in C, the expression (3 / 2) will give exactly 1. Better to simply use 1.5. Also, it's often best to avoid the pow function for simply squaring a number. So taking all that on board, try something like:
    Code:
    double a;  /* Give this a better name if you can think of one. */
     . . .
    a = 2 * i - 1;
    total += 1 / (a * a) * cos(a * M_PI * t / 3) 
    v = 1.5 - 12 / PI_SQUARED * total;
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Ethan_K View Post
    Alright yeah thanks, I'm still adjusting to syntax differences between this and matlab. I switched out the ^ for the pow function. And after I removed the & everything appears to be working correctly, so thanks guys! And just to clear things up, the & just points to a variable, right? So for most things I don't need a pointer, besides scanf()?
    & returns the address of a variable (aka, a pointer to it). With the scanf() input functions, you want to pass in an address so scanf can write to it. With the printf() output functions, you are providing a value to read. So if you have an int x, x refers to that value; &x also refers to a value, but it is the value of the address where x is stored, which is usually not meaningful for output.

    Screw around and have a look at the difference. If you are printing addresses on purpose, use %p (the p is for pointer).
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    Registered User
    Join Date
    Mar 2012
    Posts
    7
    Alright, this thread has cleared up a ton of confusions, thanks everyone!

    Edit:
    Quote Originally Posted by oogabooga View Post

    Note that because of the way integer division works in C, the expression (3 / 2) will give exactly 1. Better to simply use 1.5. Also, it's often best to avoid the pow function for simply squaring a number.
    To tell C to do double/float division it seems like putting a decimal after the numbers works (e.g. 3.0/2.0) is that correct? And for the pow function, it's better just to use multiplication because it takes less resources?
    Last edited by Ethan_K; 03-19-2012 at 08:48 AM.

  10. #10
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by Ethan_K View Post
    To tell C to do double/float division it seems like putting a decimal after the numbers works (e.g. 3.0/2.0) is that correct? And for the pow function, it's better just to use multiplication because it takes less resources?
    Yep. Sounds like you're getting the hang of it.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  11. #11
    Registered User
    Join Date
    Mar 2012
    Posts
    7
    Alright guys, everything is seemingly working correctly, as far as the compiler is concerned. However, something is going wrong when building the series: the math is going wrong after the first loop (The printf's are in there just to see what's going on in the loop). I made the series building equation it's own function to save on retyping it.

    Code:
    double buildseries(double t, int n){    
    
    
        double a=0,v=0,total=0;
    
    
        
        
        for (int i=1;i<=n;i++){
            printf("i = %d\n",i);
            a = 2.0 * i - 1.0;
            printf("a = %lf\n",a);
            total += 1.0 / (a * a) * cos(a * M_PI * t / 3.0);
            printf("total = %lf\n",total);
        }
        
        v = (3.0/2.0) - 12 / PI_SQUARED * total;
    
    
        
        return v;
    I tested the output with t = 2.4 and n = 3 and this is the output:
    i = 1
    a = 1.000000
    total = -0.809017
    i = 2
    a = 3.000000
    total = -0.774682
    i = 3
    a = 5.000000
    total = -0.734682
    t = 2.4
    n = 3
    V = 2.393266
    The a values are correct, but the total values are wrong after the first one and I'm not sure what's causing it. According to my calculator (which is in radians) the second 'total' value should be .0343352216, and the third 'total' value should be .04.

    Thanks again guys.

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is the formula that you are trying to implement? Maybe the bug is with that implementation.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    Registered User
    Join Date
    Mar 2012
    Posts
    7
    Quote Originally Posted by laserlight View Post
    What is the formula that you are trying to implement? Maybe the bug is with that implementation.
    Called Object type is not a function or function pointer (probably beginner mistake)-formula-jpg

  14. #14
    Registered User
    Join Date
    Mar 2012
    Posts
    7
    Whoops I was making a very foolish mistake and calculating the total each time while checking the math, not actual the sum of the totals each time- so everything is working fine. Time to stop late night coding...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. called object is not a function
    By tetartos in forum C Programming
    Replies: 3
    Last Post: 11-27-2011, 12:23 PM
  2. Getting Error: Called Object is not a Function
    By Ketsueki in forum C Programming
    Replies: 3
    Last Post: 06-23-2010, 05:51 AM
  3. Replies: 2
    Last Post: 08-02-2008, 09:38 PM
  4. error: called object is not a function
    By sweetorangepie in forum C Programming
    Replies: 3
    Last Post: 03-20-2008, 06:47 PM
  5. error: called object is not a function
    By yougene in forum C Programming
    Replies: 1
    Last Post: 07-24-2007, 09:32 PM