LinuxQuestions.org
Visit Jeremy's Blog.
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 08-10-2009, 04:04 AM   #1
metsarnit
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Rep: Reputation: Disabled
Question Help regarding using gcc


I am new to linux and I am trying to compile a simple C programme using gcc as a test.After using the vi editor to create the file and converting it using the gcc to an .c extension, when I give the gcc -o test test.c command these are the error messages that i get:
test.c: In function ‘main’:
test.c:3: warning: incompatible implicit declaration of built-in function ‘printf’
test.c:5: warning: incompatible implicit declaration of built-in function ‘scanf’

can someone please clear the doubt and guide as to how avoid this problem since i have to use gcc extensively from here on?
 
Old 08-10-2009, 04:17 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Can you post your code please? Perhaps the problem is that you've not included the relevant header file. You need stdio.h for both printf() and scanf(), i.e. you need a "#include <stdio.h>" at the top of your file. stdio.h contains the definitions for the functions printf() and scanf() (amongst others).

Last edited by Nylex; 08-10-2009 at 04:31 AM.
 
Old 08-10-2009, 04:39 AM   #3
metsarnit
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Original Poster
Rep: Reputation: Disabled
thanks nylex.
the code is as follows
main ()
{ int i , n;
printf("programme to print even numbers in given range");
printf("enter the upper limit: ");
scanf("%d",&n);
printf("\n\n");
for(i = 2; i<=n; i = i+2)
{ printf("\n%d\n",i);
}
}

will try it using the stdio.h header.
 
Old 08-10-2009, 07:12 AM   #4
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 08-10-2009, 08:16 AM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by metsarnit View Post
thanks nylex.
the code is as follows
main ()
{ int i , n;
printf("programme to print even numbers in given range");
printf("enter the upper limit: ");
scanf("%d",&n);
printf("\n\n");
for(i = 2; i<=n; i = i+2)
{ printf("\n%d\n",i);
}
}

will try it using the stdio.h header.
That will fix it. Also, main() should be returning int.

Edit: also, please place your code within code tags in future, to preserve indentation. It just makes it easier to read, really.

Last edited by Nylex; 08-10-2009 at 09:39 AM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile error, 'H5G_obj_t' does not name a type, is gcc 4.3 incompatible with gcc 3 ? samrat_rao Linux - Software 5 03-03-2009 02:28 PM
yum install gcc doesn't set the lastest gcc ver 4.3.x kim,jw Linux - Newbie 3 12-22-2008 11:51 PM
gcc wont install, 'failed dependencies: glibc-devel is needed by gcc-3.3.3-41' TdlSnare SUSE / openSUSE 3 11-29-2004 02:13 PM
a doubt with host gcc and arm-linux-gcc renjithgopal Linux - General 1 09-11-2003 04:02 PM
export CC=/usr/bin/gcc-3.2 - switch gcc version? ferreter Linux - Software 1 08-20-2003 12:07 AM

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

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