LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-05-2004, 08:59 PM   #1
shams
Member
 
Registered: Jan 2004
Posts: 522

Rep: Reputation: 30
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.
 
Old 08-05-2004, 09:07 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
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.
 
Old 08-06-2004, 02:34 AM   #3
Nerox
Member
 
Registered: Jul 2004
Location: Spain
Posts: 111

Rep: Reputation: 20
Hi, try to compile float y, f(float); instead of float y, float f(float);
 
Old 08-06-2004, 04:00 AM   #4
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Rep: Reputation: 15
please use code tags to post your code.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
source code for libc function dvm Programming 1 12-27-2004 06:04 PM
source code for read() function ? Mike Davies Linux - Software 1 11-03-2004 02:10 PM
LPRng error 'NONZERO RFC1179 ERROR CODE FROM SERVER' ivanscheers Linux - Networking 0 10-11-2004 02:50 AM
C code for killall function Linh Programming 3 08-01-2003 11:34 PM
What is correct code for "Include File Function" on .asp pages gregoryfrancis Linux - General 1 02-11-2003 10:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration