LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   error function in c code (https://www.linuxquestions.org/questions/programming-9/error-function-in-c-code-214047/)

shams 08-05-2004 08:59 PM

error function in c code
 
hi,
this is a function code:
#include <stdio.h>
float x=4.5;
main()
{
float y, float f(float);
x*=2.0;

y=f(x);
printf(" %f %f\n",x,y);

}
float f(float a)
{
a+=1.3;
x-=4.5;
return(a+x);

}
and this is the compilation error:
[root@localhost lbin]# gcc -o s104g s104g.c
s104g.c: In function `main':
s104g.c:5: error: parse error before "float"
s104g.c: At top level:
s104g.c:13: warning: type mismatch with previous implicit declaration
s104g.c:8: warning: previous implicit declaration of `f'
s104g.c:13: warning: `f' was previously implicitly declared to return
`int'
plz point me where is the mistake.

itsme86 08-05-2004 09:07 PM

Your mistake is right here:
Code:

float y, float f(float);
You can't define functions like that. Try moving float f(float); to somewhere above main (on a line by itself) and changing that original line to just float y;

Also, you should add return 0; to the end of your main function.

Nerox 08-06-2004 02:34 AM

Hi, try to compile float y, f(float); instead of float y, float f(float);

Kumar 08-06-2004 04:00 AM

please use code tags to post your code.


All times are GMT -5. The time now is 01:19 AM.