jsho
jsho

Reputation: 93

error: called object is not a function

Trying to make an array of arrays of floats using pointers

int main(void)
{
    int num_of_dataSets;
    float **dataSets;   
    int i;
    float *get_data;

    printf("Enter the number of data sets: \n");
    scanf( "%d " , &num_of_dataSets);
    dataSets = malloc(num_of_dataSets * sizeof(float) );

    for( i=0; i < num_of_dataSets; i++)
    {
        *(dataSets + i) = get_data();
    }

}


float* get_data()
{
    float *float_list_data;
    int j;
    int num_of_floats;

    printf("Enter the data: \n");
    scanf("%d" , &num_of_floats);

    float_list_data = malloc( num_of_floats * sizeof(float) );
    return float_list_data;
}

Getting error called object "get_data" is not a function. I can't get the error to go away. What am I missing?!

Upvotes: 0

Views: 4968

Answers (2)

Govind Parmar
Govind Parmar

Reputation: 21532

Two things:

  1. You have a local variable called get_data in your function already, in addition to the function called get_data. Rename either one of them to avoid this naming confusion.

    EDIT: It seems you don't even use the variable float* get_data; in main(). You can just remove it.

  2. If you call a function that the compiler can't find or doesn't know about, it assumes that it's just linked to from elsewhere (like, some other library that the linker knows about), and returns an int. You call get_data() before you define get_data() below main() in your code. To avoid this error, prototype the function get_data() before main(), like so:

    float* get_data();
    int main(void)
    { 
        /* Your code here */
    }
    float* get_data()
    {
        /* Your code here */
    }
    

Upvotes: 3

user2736738
user2736738

Reputation: 30906

When compiler parses your code then it gets get_data name twice once as function name and as float * too. Now when it reaches a function call it simply checks the symbol table and then it gets confused and says that it can't find the function named get_data as it was already declared as float*.

Upvotes: 2

Related Questions