Results 1 to 8 of 8

Thread: What is wrong in this little piece of C code?

  1. #1
    Join Date
    Jun 2006
    Beans
    Hidden!

    What is wrong in this little piece of C code?

    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?

  2. #2
    Join Date
    Jun 2006
    Beans
    Hidden!

    Re: What is wrong in this little piece of C code?

    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.

  3. #3
    Join Date
    Feb 2006
    Location
    Geneva, Switzerland
    Beans
    805

    Re: What is wrong in this little piece of C code?

    Compiles flawlessly on my machine...

    Hope you'll figure it out?

    - trib'
    [Why does Linux take up so much of my RAM?] [Get GNU/Linux!]
    "Software is like sex; it's better when it's free" - Linus Torvalds

  4. #4
    Join Date
    Sep 2006
    Beans
    2,914

    Re: What is wrong in this little piece of C code?

    can you do a find on your machine
    Code:
    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

  5. #5
    Join Date
    Feb 2006
    Location
    Geneva, Switzerland
    Beans
    805

    Re: What is wrong in this little piece of C code?

    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'
    [Why does Linux take up so much of my RAM?] [Get GNU/Linux!]
    "Software is like sex; it's better when it's free" - Linus Torvalds

  6. #6
    Join Date
    Jun 2006
    Beans
    Hidden!

    Re: What is wrong in this little piece of C code?

    Quote Originally Posted by tribaal View Post
    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).

  7. #7
    Join Date
    Jan 2006
    Location
    Leuven, Belgium
    Beans
    3,414

    Re: What is wrong in this little piece of C code?

    It's build-essential, you can find it in main.

  8. #8
    Join Date
    Jun 2006
    Beans
    Hidden!

    Re: What is wrong in this little piece of C code?

    Alright! I installed build-essential and now it compiled. Thanks for your help.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •