PDA

View Full Version : What is wrong in this little piece of C code?


jincast90
March 4th, 2007, 08:50 AM
Hello. I have written this following piece of code:

#include <stdio.h>

int main()
{
char key;

puts("Type your favorite keyboard character");
scanf("%c",&key);
printf("Your favorite character is %c!\n",key);
return(0);
}

After trying to compile using this command: "gcc favkey1.c -o favkey1" I get the following error:

favkey1.c:1:19: error: stdio.h: No such file or directory
favkey1.c: In function ‘main’:
favkey1.c:8: warning: incompatible implicit declaration of built-in function ‘scanf’
favkey1.c:9: warning: incompatible implicit declaration of built-in function ‘printf’


Can anyone tell me what is wrong in my source code?

jincast90
March 4th, 2007, 08:54 AM
I was thinking maybe something is set up wrong with the compiler or such, because I remember a couple a weeks ago my laptop would not compile some source code, but my Desktop would compile it just fine.

tribaal
March 4th, 2007, 08:59 AM
Compiles flawlessly on my machine...

Hope you'll figure it out?

- trib'

ghostdog74
March 4th, 2007, 09:03 AM
can you do a find on your machine

find / -type f -name "stdio.h" -print

see if there are results. If nothing at all, you have installed gcc incorrectly i guess. pls reinstall. If there are stdio.h, you can look at where its stored, the include the path in your environment

tribaal
March 4th, 2007, 09:08 AM
Make sure you installed "build-essentials", not only the "gcc" package.
Build-essentials installs the standard C library and lots of other things, while the GCC package only installs gcc itself...

Hope this is the problem :)

- trib'

jincast90
March 4th, 2007, 09:20 AM
Make sure you installed "build-essentials", not only the "gcc" package.
Build-essentials installs the standard C library and lots of other things, while the GCC package only installs gcc itself...

Hope this is the problem :)

- trib'

I tried doing a "aptitude search build-essentials" but nothing came up. So where should I get it?

And to ghostdog74, I didn't install gcc, it was installed with Ubuntu. (From the live cd).

Ramses de Norre
March 4th, 2007, 10:01 AM
It's build-essential, you can find it in main.

jincast90
March 4th, 2007, 10:27 AM
Alright! I installed build-essential and now it compiled. Thanks for your help.