> For the complete documentation index, see [llms.txt](https://ruggedboard.gitbook.io/ruggedboard/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ruggedboard.gitbook.io/ruggedboard/tutorial-using-c/hello-world/write.md).

# Write your first C program

**Step 1: Find a suitable text editor that suits you eg: Atom, Sublime text, vim, notepad ++, etc..**

![](https://3507971843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbvnQRGvCTc2Zmsi6BG%2F-LeVhH1CXsYmlJrhymLv%2F-LeVhi9tgdbxWIgKXqv1%2FC_1.png?alt=media\&token=105c654d-534e-44df-a7a1-21ae6437fd0e)

**Step2: Write a small C code on your HOST PC and save it with a** `.c` **extension(eg:** `hello.c`**). You can try our example code given below:**

```
#include <stdio.h>
int main()
{
	printf("Hello board!!\n");
	return 0;
}
```

![](https://3507971843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbvnQRGvCTc2Zmsi6BG%2F-LeVhH1CXsYmlJrhymLv%2F-LeVhnUam8CHOtkuAW6u%2FC_2.png?alt=media\&token=e5b27c15-0915-4b17-bbd0-f6b2776d91cc)

**Step 3: Open your terminal (ctrl + alt + T), navigate to the Toolchain folder and untar the** `gcc-linaro-7.3.1-2018.05-i686_arm-linux-gnueabihf.tar.xz`**file using the command** `tar -xvf gcc-linaro-7.3.1-2018.05-i686_arm-linux-gnueabihf.tar.xz`**.**

![Untarring Toolchain](https://3507971843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbvnQRGvCTc2Zmsi6BG%2F-LeVhH1CXsYmlJrhymLv%2F-LeVj9U8MwB6kLW609QW%2Funtar_toolchain.png?alt=media\&token=8de18be3-6e53-46a1-aa15-a83236655c3d)

![After untarring Toolchain](https://3507971843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbvnQRGvCTc2Zmsi6BG%2F-LeVhH1CXsYmlJrhymLv%2F-LeVjIN4UUTTqVRFr6MY%2Funtarred.png?alt=media\&token=16cdd1cc-6930-4cfa-b34c-9c7fff5a29c0)

**Step 4: Navigate to the mentioned folder** `/Toolchain/gcc-linaro-7.3.1-2018.05-i686_arm-linux-gnueabihf/bin`**and then type in** `pwd`**and copy the path that appears.**

![](https://3507971843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbvnQRGvCTc2Zmsi6BG%2F-LeVhH1CXsYmlJrhymLv%2F-LeVjn7-_C_jWTz3bSpA%2Fpath_env.png?alt=media\&token=847bbe14-94d0-42d4-b233-3a2eb8e4aaa4)

**Step 5: Open the** `env.sh`**file and paste the copied path to the corresponding line.**

![](https://3507971843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbvnQRGvCTc2Zmsi6BG%2F-LeVhH1CXsYmlJrhymLv%2F-LeVm0V13gWhX23VFG6U%2Fenv.png?alt=media\&token=f766e65d-8027-4f31-94aa-dc07734e5f94)

**Step 6: Run the** `env.sh`**file by using the command** `. env.sh`**.**\
**Make sure the the toolchain is running on your PC by typing "arm" and hitting the \<TAB> key twice.**&#x20;

![Enabled Toolchain](https://3507971843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbvnQRGvCTc2Zmsi6BG%2F-LeVhH1CXsYmlJrhymLv%2F-LeVmRBgy6CAIdbeVQ50%2Ftool_chain.png?alt=media\&token=92f8cc46-401e-4aad-ae56-e24a10e8c1f7)

**If the toolchain isn't running you'll only see a very few of them.**\
**NOTE: Do not close or switch your terminal as it will disable the toolchain that is running. We need to compile the C file with the enabled toolchain to get an executable that can be executed on the Board, as our PC is an X86 architecture and the board is an ARM architecture.**

**Step 7: Navigate back to your C folder and compile the C code using the toolchain enabled terminal.**\
&#x20;`arm-linux-gnueabihf-gcc hello.c -o hello_board` &#x20;

![](https://3507971843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbvnQRGvCTc2Zmsi6BG%2F-LeVhH1CXsYmlJrhymLv%2F-LeVoWnUZRYEv5PJuzFJ%2Fcompile_c.png?alt=media\&token=936a2a42-666a-49e7-babf-d14dc5da1a0b)

**Step 8: Copy the file to** `/var/lib/tftpboot`**. Type in** `cp hello_board /var/lib/tftpboot`**to copy the binary.**

![](https://3507971843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbvnQRGvCTc2Zmsi6BG%2F-LeVhH1CXsYmlJrhymLv%2F-LeVpLDv4f3g1l6Tr_Hm%2Ffile_in_tftpboot.png?alt=media\&token=5972a519-ceff-4635-9e9f-d5d9aecac09e)

**Step 9: Open a Terminal on the board, Transfer the compiled binary `"hello_board"` to the board either by TFTP or by SD Card. (**[**Click here to follow the process to transfer files from Host to Board**](/ruggedboard/tutorial-using-c/hello-world/transferring-files-from-host-to-board.md)**)** \
**Now you can see your binary on the rootfs of the board.**

![](https://3507971843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbvnQRGvCTc2Zmsi6BG%2F-LeVhH1CXsYmlJrhymLv%2F-LeVnMIgmEAqXCPluZaf%2Ftftp_board.png?alt=media\&token=e70b768f-7281-417f-b83f-c43b531e8898)

**Step 10: Give the necessary permissions** `chmod +x hello_board`

**Step 11: Run the binary using** `./hello_board`&#x20;

![You just said hello to your board! :)](https://3507971843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbvnQRGvCTc2Zmsi6BG%2F-LeVhH1CXsYmlJrhymLv%2F-LeVqTqWM97G0fYRYMX-%2Fc_out.png?alt=media\&token=3d919062-4075-44a7-8e4b-246c98582aff)

**------------------Congratulations on running your first C program on the Board!!--------------------**
