Simple error around which I can't wrap my head.

This is a discussion on Simple error around which I can't wrap my head. within the Linux Programming forums, part of the Platform Specific Boards category; I installed Ubuntu in my PC a while ago and only now have I started programming in C. So, I ...

  1. #1
    Registered User KAUFMANN's Avatar
    Join Date
    Jan 2011
    Location
    Coimbra, Portugal
    Posts
    31

    Simple error around which I can't wrap my head.

    I installed Ubuntu in my PC a while ago and only now have I started programming in C.


    So, I did as instructed:

    use gedit to write the code, save it in .c format, open the terminal, write
    $cc -c example.c
    $cc -o pun pun.c
    $./pun.c

    But it doesn't work. It return an error that I didn't do.

    No matter what my code is, it always this error:

    Code:
    presidente@presidente-1005HA:~$ cc -c pun.c
    presidente@presidente-1005HA:~$ cc -o pun pun.c
    presidente@presidente-1005HA:~$ ./pun.c
    ./pun.c: line 2: syntax error near unexpected token `('
    ./pun.c: line 2: `int main(void){'
    presidente@presidente-1005HA:~$
    The code hasn't got any errors or bugs whatsoever, so why does it always say "syntax error near unexpected token `(' "
    ˙uıɐƃɐ ʎɐq-ǝ ɯoɹɟ pɹoqʎǝʞ ɹǝɥʇouɐ ƃuıʎnq ʇou ɯı

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You don't run the C source, you run "pun" itself (the executable you get from the second step).

  3. #3
    Registered User KAUFMANN's Avatar
    Join Date
    Jan 2011
    Location
    Coimbra, Portugal
    Posts
    31
    Quote Originally Posted by tabstop View Post
    You don't run the C source, you run "pun" itself (the executable you get from the second step).
    Silly me...

    Thank you indeed!
    ˙uıɐƃɐ ʎɐq-ǝ ɯoɹɟ pɹoqʎǝʞ ɹǝɥʇouɐ ƃuıʎnq ʇou ɯı

  4. #4
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    506
    Quote Originally Posted by KAUFMANN View Post
    So, I did as instructed:
    use gedit to write the code, save it in .c format, open the terminal, write
    $cc -c example.c
    $cc -o pun pun.c
    $./pun.c
    Slight redundancy here... when you run cc -c example.c that gives you an object file, example.o, then you run cc -o pun pun.c (ignoring the newly created object file example.o) which compiles pun.c into pun (without the need of a 2 step object->link manual process using the -c parameter then linking)

    Kinda odd that you are doing that?

    Code:
    presidente@presidente-1005HA:~$ ./pun.c
    ./pun.c: line 2: syntax error near unexpected token `('
    ./pun.c: line 2: `int main(void){'
    presidente@presidente-1005HA:~$
    To explain what is going on here is that the C source file is trying to be interpreted as a script by the default shell interpreter in your environment....

    Whats really strange is that the source code has the executable bit set in the first place? What I mean is that you SHOULD
    of gotten a Permission Denied error letting you know that executing that file is not allowed based on file permissions.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple program, simple error? HELP!
    By colonelhogan44 in forum C Programming
    Replies: 4
    Last Post: 03-21-2009, 12:21 PM
  2. It's a wrap!
    By Salem in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 06-10-2007, 03:00 PM
  3. Word Wrap
    By Fireblade2006 in forum C++ Programming
    Replies: 2
    Last Post: 02-27-2006, 03:09 PM
  4. Word wrap
    By Orrill in forum C++ Programming
    Replies: 6
    Last Post: 10-14-2005, 03:00 PM
  5. Word Wrap
    By sethjackson in forum Windows Programming
    Replies: 4
    Last Post: 09-21-2005, 05:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21