Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Code:Blocks syntax error

  1. #1
    Join Date
    Jan 2014
    Beans
    6

    Code:Blocks syntax error

    I am doing some *very* basic coding in C using code blocks. I kept running into a syntax error, even on something as fundamental as a hello, world:

    #include <stdio.h>

    main ()

    {

    printf("tests");
    return 0;

    }

    I compile it, change permission on the file, and get this error:

    syntax error: word unexpected (expecting ")"

    Some poking around indicates this may arise from choosing the wrong compiler-- I chose the GNU GCC Compiler.

    I am running Ubuntu 13.10
    Processor : Intel® Core™ i5-4200M CPU @ 2.50GHz × 4
    OS type : 64 bit

    Can anyone point me in the right direction? I'm stumped.

  2. #2
    Join Date
    Jun 2010
    Location
    Loznica Serbia
    Beans
    126
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Maddening Problem with Code:Blocks syntax error

    Could you post the exact steps you used to compile your program, you might be trying to run the wrong file.
    Usually you do it like this:
    Code:
    gcc file.c -o executable
    ./executable
    Or why don't you just run it from codeblocks, it does these things automatically.
    Also, main should return int, so you should use
    Code:
    #include <stdio.h>
    
    int main ()
    
    {
    
    printf("tests");
    return 0;
    
    }
    in your code
    Last edited by nidzo732; January 23rd, 2014 at 09:02 AM.

  3. #3
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Maddening Problem with Code:Blocks syntax error

    Works for me with GCC. It could be some invisible control character(s) (your code has a rather unusual formatting, with a lot of spaces and line feeds).
    Warning: unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.

  4. #4
    Join Date
    Jan 2014
    Beans
    6

    Re: Maddening Problem with Code:Blocks syntax error

    Quote Originally Posted by nidzo732 View Post
    Could you post the exact steps you used to compile your program, you might be trying to run the wrong file.
    Usually you do it like this:
    Code:
    gcc file.c -o executable
    ./executable
    Or why don't you just run it from codeblocks, it does these things automatically.
    Also, main should return int, so you should use
    Code:
    #include <stdio.h>
    
    int main ()
    
    {
    
    printf("tests");
    return 0;
    
    }
    in your code
    I have been using code blocks to compile/run. Basically, I build it, then I have to change permission on the file (code blocks doesn't seem to make it executable), then run it. When I run it (using code blocks) I get that error.

    When I added int, it says Syntax error "(" unexpected. The maddening thing here is that it compiles, or appears to. I get this error when running.

  5. #5
    Join Date
    Jun 2010
    Location
    Loznica Serbia
    Beans
    126
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Maddening Problem with Code:Blocks syntax error

    Could you run it from the terminal like I wrote above (the first code). Replace "file.c" with the name of your file.
    If it goes wrong, post the entire contents of the terminal here.

  6. #6
    Join Date
    Jan 2014
    Beans
    6

    Re: Maddening Problem with Code:Blocks syntax error

    Quote Originally Posted by nidzo732 View Post
    Could you run it from the terminal like I wrote above (the first code). Replace "file.c" with the name of your file.
    If it goes wrong, post the entire contents of the terminal here.
    Here's when I get:

    Code:
    toddbert@toddbert-ubuntu:~/Documents$ ./Testicles
    ./Testicles: line 2: syntax error near unexpected token `('
    ./Testicles: line 2: `int main ()'
    (yes, I am two years old with the filenames)

    I feel this is some thing I am missing with setup or permissions or something weird like that. This progam is simply too simple to not 'just work'.
    Last edited by toaster3; January 23rd, 2014 at 09:32 AM.

  7. #7
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Code:Blocks syntax error

    it looks like you made the source code file executable, and tried to run that

  8. #8
    Join Date
    Jan 2014
    Beans
    6

    Re: Code:Blocks syntax error

    Quote Originally Posted by steeldriver View Post
    it looks like you made the source code file executable, and tried to run that

    Ok, forgive me a little here, but what is Code Blocks meant to spit out when you hit 'compile and run'? Where is the acutal executable file meant to end up? I'm literally building a single file (there's no project or anything fancy here). This is making me feel incredibly dippy, as 'hello world' should just sort of run, shouldn't it?

  9. #9
    Join Date
    Jun 2010
    Location
    Loznica Serbia
    Beans
    126
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Code:Blocks syntax error

    The executable is in PROJECT_FOLDER/bin/Debug.
    You're not supposed to run the source code itself.
    You can compile the source manually, without codeblocks
    Code:
    cc Testicles.c -o Testicles 
    ./Testicles
    Last edited by nidzo732; January 23rd, 2014 at 09:54 AM.

  10. #10
    Join Date
    Jan 2014
    Beans
    6

    Re: Code:Blocks syntax error

    Quote Originally Posted by nidzo732 View Post
    The executable is in PROJECT_FOLDER/Bin/Debug.
    You're not supposed to run the source code itself
    Then there is no executable:

    /home/toddbert/Documents
    toddbert@toddbert-ubuntu:~/Documents$ ls
    Testicles
    toddbert@toddbert-ubuntu:~/Documents$

    So it's obviously failing to compile, period.

    Ok. It compiles outside of Code Blocks:

    Code:
    toddbert@toddbert-ubuntu:~/Documents$ cc Testicles.c -o Testicles
    toddbert@toddbert-ubuntu:~/Documents$ ./Test
    bash: ./Test: No such file or directory
    toddbert@toddbert-ubuntu:~/Documents$ ./Testicles
    Test

    So, hooray. As to why it won't compile and run IN Code Blocks, well, that's a bit of a quandary. Furthermore, if I name the file <filename>.c in Code Blocks, the 'build' toolbar is greyed out. If I name it <filename> with no extension, it is there.

    Looks like I have some more reading to do about Code Blocks, I guess. Unless somone here has a quick answer to that question, I thank everyone for making my first question here a pleasant one.
    Last edited by toaster3; January 23rd, 2014 at 10:06 AM.

Page 1 of 2 12 LastLast

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
  •