ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 .
[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 ).
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!!!)
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 ! .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.