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,
If you want to compile it using Terminal, Open the terminal (Press CTRL + ALT + T).
Go to the directory where the file is saved. (You can use cd command to change directory).
After reaching the directory , type
gcc file1.c
.If there are no errors, then you can run the output by typing
./a.out
.
Related videos on Youtube
![BeGood](https://lh3.googleusercontent.com/-i2ltH3fRfFU/AAAAAAAAAAI/AAAAAAAAAAA/8DNqEpXTT9M/photo.jpg?sz=256)
Author by
BeGood
Updated on September 18, 2022Comments
-
BeGood almost 2 years
This is my first time using Ubuntu to run a C-File with a codeBlocks
I tried save as a File "file1" without extension file.
Permission Denied
I tried chmod u+x file1
Wrong something but builded success
I tried give "file1.c"
File not found
-
muru about 9 yearsDid you build after saving it as
file1.cpp
? Is it even building correctly? -
Snake Eyes about 9 yearsOpen the terminal ----> Go to the location of the file -----> type
g++ file1.cpp
and c file is saved with.c
extention not.cpp
. -
BeGood about 9 years@muru all Correctly
-
BeGood about 9 years@Hunter Look like gpeddit with Terminal right
-
Snake Eyes about 9 yearsgedit 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 about 9 years@Hunter Yes already gcc and g++
-
Snake Eyes about 9 yearsIs it c++ program or c program?
-
BeGood about 9 years@Hunter c program
-
karel about 9 yearsFollow all the steps in the Code::Blocks Creating a new project wiki at codeblocks.org and please comment if it doesn't work.
-
BeGood about 9 years@karel yes i did. new Project > Console program > C > run main.c (Helloworld). Result /.../Debug: File not found
-
BeGood about 9 yearsso Codeblocks can't complie itsefl?
-
Snake Eyes about 9 yearsYes, it Can compile , You can use the "Build" option to compile
-
Eliah Kagan almost 7 yearsUsers 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 differentchmod
command would be needed as well.