Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting a 'called object 0 is not a function error'?

Tags:

c

I'm a C# developer trying to learn C (followed by C++). I am going native, working on Ubuntu using vim as my text editor, and the Gnu C Compiler (gcc) to compile.

I'm trying to write a simple Celcius => Fahrenheit converter and I am getting the following error:

called object '0' is not a function

My code is as follows:

#include <stdio.h>

main()
{
    for(int i = 0; i < 300; i+20)
    {
        int celcius = (5/9)(i-32);
        printf("%d - %d \n", i, celcius);
    }
}

I am compiling with this:

gcc FahrenheitToCelcius.c -std=c99

Could somebody point what I'm doing wrong here?

Thanks

like image 476
Badger Avatar asked Feb 26 '26 20:02

Badger


2 Answers

As people have pointed out

int celcius = (5/9)(i-32);

Should be

int celcius = (5/9)*(i-32);

However the reason you are getting that particular error message is that

int celcius = (5/9)(i-32);

is being evaluated at run time as

int celcius = (0)(i-32);

And the runtime system sees (0) as a pointer.

So you need to change your math to avoid the integer division

like image 63
Peter M Avatar answered Mar 01 '26 10:03

Peter M


In C (and I am assuming that in other languages too :)) an arithmetic operator is needed to perform an arithmetic operation.
Change

int celcius = (5/9)(i-32);

to

int celcius = (5/9)*(i-32);
like image 22
haccks Avatar answered Mar 01 '26 11:03

haccks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!