Run C Program on android with termux

Termux is an Android terminal emulator.
    The answer to the question " How to create and run C program in Android device? " Is here.
To run C programs in android using Termux requires the installation of two termux packages.
- clang : 
The Clang tool is a front-end compiler that is used to compile programming languages such as C, C++, Objective C and Objective C++ into machine code.

- Nano : 
Text Editor to create a file

How To Run C Programs on Android, How to install C/C++ in Android using Termux


WHAT We will learn ?

  • Termux Installation 
  • Update and Upgrade Termux
  • Install  packages for C language 
  • Develop Simple C Program using Nano text editor in Termux
  • Run C Program 
  • Tips – Solution for “E: Unable to locate package clang” Error

Before we learn How to run the C program on android, let's take a look at Some Important Termux commands we must remember:

- To clear all screen content run the command.
$ clear

- To find current working directory.
$ pwd

- To change our current working directory to another directory. Here I’m moving in /java directory/folder.
$ cd /java

- If you want one directory/folder to move
$ cd..

- If you want to back two directories use.
$ cd ../../

- To Create New File: To Create New Directory/Folder use mkdir commad Stands for make a new directory.
$ mkdir <new-directoy-name>

- To Delete Directory/Folder in Termux
$ rmdir <directory-name>    

- To delete File
$ rm <file-name>

Check this one: Amazing fact of Switch statement in C

Here is How You Can Write and Run C Programs on Your Android Devices 

Step 1: Install Termux from Google Play 

Update: Play Store Version of Termux is Deprecated. Due to Android 10 issues, Termux and its plugins are no longer updated on the Google Play Store and have been deprecated. The most recent version for Android >= 7 was v0.101. It is strongly advised not to install Termux apps from the Play Store any longer. 
Download From:
- F-Droid : F-Droid is a robot with a passion for Free and Open Source Software (FOSS) on the Android platform.
Click here to dowload F-Droid and get Termux.
Github :
Click here to get termux from Github

Step 2: Now Update and Upgrade Termux
    - Open Termux
    - To Update Termux type command 
        $ apt update
    - To Upgrade Termux type command
        $ apt upgrade

Step 3: Open Termux app and install clang and nano package  to create        and run C program
    $ apt install clang
    - This will install clang package 
    $ pkg install nano 
    - This command will install nano text editor if not available.

Step 4: To create C program file with .c extension
    - Type $ nano learnc.c
    - This will create learnc.c file and open file in nano text editor.
    - Now write simple C program in nano text editor as given below.

        #include <stdio.h>
        int main()
            {
           printf("Welcome to C programming Learning World with Computer-Bits-Daily");
           return 0;
            }

    - Press Ctrl + s to save file and Ctrl +x to exit nano text editor.

Step 5: To compile your c program 

Type $ gcc learnc.c -o myoutput  command and press Enter
    - Here, The option -o is used to specify the output file name. If we do not use this option, then an output file with name a.out is generated.
    - In the above command myoutput is output filename.

Step 6: To run your c program 
      $ ./ myoutput
    - In the above command myoutput is file name generated when we compile learnc.c file
    - You will get output “Welcome to C programming Learning World with Computer-Bits-Daily”

Step 7: To exit Termux type command 
    $ exit

Learn by Watching Video Tutorial on how to create and run C program On Termux. 


Possible solution for  “E: Unable to locate package clang” Error

  • Solution 1: use $ apt update command and then try to install package
  • Solution 2: use $ pkg upgrade command and then try to install package
  • Solution 3: use $ termux-change-repo command and then try to install package
  • Solution 4: use $ pkg install root-repo command and then try to install package
  • Solution 5: use $ termux-setup-storage command and then try to install package

Free Full C Programming Course With best Android app: Computer Courses
Computer Bits Daily

Now you’re ready to Run the C program On Termux. Happy Coding | Keep Learning |Keep Sharing | Stay Safe!

Dear Me - Inspiring Beats...!

Post a Comment

0 Comments