This short tutorial introduces you how to install a C compiler plus a text editor to do C programming on Ubuntu. The compiler is GNU gcc and the editor is Geany. Don't worry, this tutorial is intended for beginners and easy to follow. I will show you how to compile a .c source code file until executing it using Geany. Happy learning!
Subscribe to UbuntuBuzz Telegram Channel to get article updates directly.
1. Install Compiler
Do it:
$ sudo apt-get install -V gcc
2. Install Editor
Do it too:
$ sudo apt-get install geany
3. Write
Now run Geany and write this short lines of code. Save it as program.c.
#include <stdio.h>
int main()
{
printf("hello, C programming!\n"); // print to screen
return 0;
}
4. Compile
Now, compile your source code. Press Compile button, then press Build button. If your source code is free from errors, this compilation should produce a file named program without extension on the same folder as your .c file. See GIF animation below.
- What's Compile button? Pressing this button is the same as gcc -c program.c that produces a file named program.o. This file is called object file.
- What's Build button? Pressing this button is the same as gcc -o program program.c that produces the final file named program. This file is called binary executable file.
- What's Run button? Pressing this button is the same as ./program that is executing the binary executable file.
5. Run
Now press Run button. This should open a Terminal and show the output of your code. The output should say hello, c programming! . If this is your first experience with programming, welcome to C and keep learning!
C Source Code Examples
Where to get .c sources on the net? If you have a textbook about C, just type the source code available there. But if you don't have any, go to http://cprogramming.com. They have enough C source codes arranged in chapter by chapter that are suitable for beginners. Learn them one by one!