Embedded System - Raspberry Pi





C Programming


In this tutorial, I will show you how to create a very simple C program and compile & run it on Rasphberry Pi. Once this is done, all of the remaining thing would be to study about C language itself. It is nothing to do with Raspberry Pi. Refer to my notes on C for the details of C language itself.



Step 0


Before you start trying this tutorial, first make it sure that your Raspberry pi OS is installed with gcc as shown below.




Step 1


Run a text editor tool and create file (In this tutorial, I used nano editor and created file named helloworld.c). To do this just type in following command on command line.

    # sudo nano helloworld.c

Then you will get a editor program opening as follows.





Step 2


Write a program as you like. (I tried my favourite Helloworld)




Step 3


Save and Exit the editor. To do this, try folowings


i) Press Ctrl + X (meaning Exit), and you will get the following menu as shown at the bottom




ii) Press Y (meaning Yes). Then you will get the following menu at the bottom




iii) Press Ctrl+T (meaning ToFiles), then you will get the list of files shown as below.




iv) select the file name (helloworld.c) as shown above and hit Enter.



Step 4


List the files in the directory and see if the source code file is created as shown below.




Step 5


Compile the source code as shown below.




Step 6


Check if the compiled program is created as shown below.





Step 7


Test the program as shown below.





Reference :