Monday, July 9, 2018

Have I Really Forgotten C?


int main (argc, char ** argv)
    float x,y;
    for (x=-2.25f; x<= 2.25f; x+=.1f)
        y = pow(x, 2)-x);
        printf("%0.2f %0.2f\n", x, y);

pow is "undefined reference to 'pow'

I needed -lm on the cc line. Thanks.


Cincinnatus said...

Was the space in the include file name "math .h" in your original source? If so, that's your error.

Cincinnatus said...

Also, using quotes instead of brackets means it looks in local directory for file instead of the compiler include search path.

Paul Sand said...

Ooh, ooh, I know! (Maybe.)

Add the '-lm' flag to your cc step to link in the math library.

Also "#include "

smn said...

In the text shown, the parenthesis are not balanced where y is evaluated. I see an extra ) before the semicolon at the end of the expression.

Jeff Dege said...

Do you have a local math.h file?

Eskyman said...

These expressions aren't allowed in The New Math. Haven't you heard?

There's a new law coming soon, which will set Pi=3.0 That'll make everything much simpler, won't it!