How do I run my C program?

You need to compile your program before you can run it. To do this, you'll need a C compiler, like gcc. You can install this with:

sudo apt-get install gcc

Then, to compile your program, creating an executable called file:

gcc -Wall -o file file.c

Which you should then be able to run:

./file

Fabrice Bellard's TCC seems to be still in the repositories. It can run in a kind of interpreter-mode which makes the following possible:

You can make a simple C-file executable like the OP tried to do by adding the line

#!/usr/bin/tcc -run

to the very top of the file.

It also accepts input from STDIN by adding an empty option (just the minus sign -) at the end.

$ /usr/bin/tcc -run - <<EOF
> #include <stdio.h>
> int main()
> {
>    printf("Hello World\n");
>    return 0;
> }
> EOF
Hello World

or with echo

echo '#include <stdio.h> int main(){printf("Hello World\n");return 0;}' | /usr/bin/tcc -run -

or just run /usr/bin/tcc -run - type your code and start the run with CTRL + D

Seems useless and silly but the last method is the fastest (for me, YMMV etc.) to check for a function in a large library, look up the exact value of a constant etc. And it is small (180k) which makes it a good fit for e.g. the Raspberry-Pi.

Main disadvantage: development stopped (last version is from 2013).


AFAIK, you have to compile C code before executing it like so:

gcc file.c