How can I run a C program from Code Blocks?

5,790

First of all, Any C program is saved with .c Extension. And C++ program is saved with .cpp extension.

Now coming to compilation,

  1. If you want to compile it using Terminal, Open the terminal (Press CTRL + ALT + T).

  2. Go to the directory where the file is saved. (You can use cd command to change directory).

  3. After reaching the directory , type gcc file1.c.

  4. If there are no errors, then you can run the output by typing ./a.out.

Share:
5,790

Related videos on Youtube

BeGood
Author by

BeGood

Updated on September 18, 2022

Comments

  • BeGood
    BeGood almost 2 years

    This is my first time using Ubuntu to run a C-File with a codeBlocks

    1. I tried save as a File "file1" without extension file.

      Permission Denied

    2. I tried chmod u+x file1

      Wrong something but builded success

    3. I tried give "file1.c"

      File not found

    • muru
      muru about 9 years
      Did you build after saving it as file1.cpp? Is it even building correctly?
    • Snake Eyes
      Snake Eyes about 9 years
      Open the terminal ----> Go to the location of the file -----> type g++ file1.cpp and c file is saved with .c extention not .cpp.
    • BeGood
      BeGood about 9 years
      @muru all Correctly
    • BeGood
      BeGood about 9 years
      @Hunter Look like gpeddit with Terminal right
    • Snake Eyes
      Snake Eyes about 9 years
      gedit is a text Editor. It is not a compiler. Have u installed any compiler like clang (for c) or gcc (for c) or g++ (for C++)?
    • BeGood
      BeGood about 9 years
      @Hunter Yes already gcc and g++
    • Snake Eyes
      Snake Eyes about 9 years
      Is it c++ program or c program?
    • BeGood
      BeGood about 9 years
      @Hunter c program
    • karel
      karel about 9 years
      Follow all the steps in the Code::Blocks Creating a new project wiki at codeblocks.org and please comment if it doesn't work.
    • BeGood
      BeGood about 9 years
      @karel yes i did. new Project > Console program > C > run main.c (Helloworld). Result /.../Debug: File not found
  • BeGood
    BeGood about 9 years
    so Codeblocks can't complie itsefl?
  • Snake Eyes
    Snake Eyes about 9 years
    Yes, it Can compile , You can use the "Build" option to compile
  • Eliah Kagan
    Eliah Kagan almost 7 years
    Users generally own the files they create automatically, and compilers automatically set execute permissions on the executable binaries they create (unless they can't, for example due to the filesystem not supporting it, in which case manually running chmod +x will also fail). A compiler might not make the program executable for the user if umask is set unusually, but then a different chmod command would be needed as well.