LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 11-26-2007, 07:35 PM   #1
doanhanam
LQ Newbie
 
Registered: Nov 2007
Posts: 2

Rep: Reputation: 0
help me !


I am newbe in the Linux , I use gcc to compile the simple following code but it sai that the fmod() unreferenced . I guess that something wrong with the include file . But i do not know .
#include "stdio.h"
#include <math.h>
void main()
{
int i = fmod(12,2);
printf("%d",i);
}

and I use the simple command to compile : gcc check.c
And the error occur .
I use fedora and I use emacs check.c at the root directory .
Thank you and have nice day .
 
Old 11-26-2007, 07:49 PM   #2
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
1) post titles with a descriptive topic, not "help!!!" or "help me"

2) post the exact error (copy it from the terminal) message

3) if its the error i think it is, try "gcc check.c -lm"
 
Old 11-26-2007, 09:17 PM   #3
milky.way
LQ Newbie
 
Registered: Nov 2007
Posts: 13

Rep: Reputation: 0
why "stdio.h" and not <stdio.h> ???
do you have the stdio.h file in this folder ???
 
Old 11-27-2007, 04:19 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
you need to link the math library,

do this...

(I assume your file is called check.c?)
Code:
export LDFLAGS=-lm
make check
 
Old 11-27-2007, 07:50 AM   #5
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
[quote]> gcc -o check check.c -lm
check.c: In function ‘main’:
check.c:4: warning: return type of ‘main’ is not ‘int’[/code]
Code:
#include <stdio.h>
#include <math.h>
main()
{
   int i = fmod(12,2);
   printf("%d",i);
}
As mentioned previously it should, probably, read <math.h> and compile with
Quote:
cc -o check check.c -lm
that will get rid of the error message that you were getting.

Removal of void from void main() will prevent of the warning about the return type of 'main'.
I will of course follow up on your comments too Billy. You're not noted for speaking without having something worthwhile to say however, and I would hate you to feel your efforts were wasted. A bit like casting Perl among . . . ( It's just not near the top of my reading list - oink! )

Doanhanam, you might also find it helpful to put a newline '\n' in the format string of printf. it will make it easier to read/notice the output, which otherwise will hide behind the your terminal monitor prompt.

Billy, any thoughts about about the return type of main(), can I assume that the default return type expected is int? ( More reading for me ).

Last edited by PAix; 11-27-2007 at 07:53 AM.
 
Old 11-27-2007, 07:57 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
I believe, that the default type for each and every function is int unless otherwise
specified.

I think
main()

maps to

int main(void)

but it's only a warning, just sling a return 0; on the end of the main.
it's good practice to return 0 for OK, otherwise non zero.
(this is to the operating system, of course internally in C the truth is reversed!!!)
 
Old 11-27-2007, 05:11 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Here's a good ref list: http://members.aol.com/wantondeb/#MAIN
 
Old 11-27-2007, 06:38 PM   #8
doanhanam
LQ Newbie
 
Registered: Nov 2007
Posts: 2

Original Poster
Rep: Reputation: 0
thank you for the precious help . I have try and It runs correctly .
I am very happy to continue programming in Linux . In viet Nam , little programmers use Linux because they are used to Windows . My classmates seldom program on this environment . And I get more confident when joining this forum . Thank you a lot for all .
Have good day ! .
 
Old 11-28-2007, 02:45 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Quote:
In viet Nam , little programmers use Linux because they are used to Windows .
it's the same the world over.
leave them to their virus-scanners I say.

the art of unix programming
 
  


Reply



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



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

All times are GMT -5. The time now is 01:20 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