Last active
February 20, 2026 17:11
-
-
Save VirajKanse/1c0db872cd7685632c02f8826397f190 to your computer and use it in GitHub Desktop.
GCC / Clang C/C++ Compiler On Android Using Termux (Linux Environment)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Install Termux App. | |
| type "apt update" | |
| Then We have to install a text editor to write our code so type "apt install vim" for vim text editor | |
| or u can also use nano text editor for nano type "apt install nano" | |
| Now Clang Installation type "apt install clang" and wait for download completes. | |
| now to create a file simply type vim filename.c or .cpp or nano filename.c or cpp | |
| then u will able to write ur code . | |
| write.....to save ur code simply press esc then type ":wq" | |
| now code is ready to compile | |
| type "clang filename.c -o filename" | |
| If ur code is right then it will be compiled. | |
| Else it will show error.fix it. | |
| To run ur program simply type "./filename". | |
| Tada...Done. | |
| 1. apt update | |
| 2. apt install vim or nano | |
| 3. apt install clang | |
| 4. vim/nano filename. | |
| 5. clang filename.c -o filename | |
| 6. ./filename |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <time.h>
int kbhit(void) {
struct termios oldt, newt;
int ch;
int oldf;
}
int getch() {
struct termios oldt, newt;
int ch;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return ch;
}
int width = 20, height = 20;
int x, y, fruitX, fruitY, score;
int tailX[100], tailY[100];
int nTail;
int gameOver;
enum direction {STOP = 0, LEFT, RIGHT, UP, DOWN};
enum direction dir;
void Draw() {
system("clear");
}
void Setup() {
gameOver = 0;
dir = STOP;
x = width / 2;
y = height / 2;
srand(time(0));
fruitX = rand() % width;
fruitY = rand() % height;
score = 0;
}
void Input() {
if (kbhit()) {
switch (getch()) {
case 'a': dir = LEFT; break;
case 'd': dir = RIGHT; break;
case 'w': dir = UP; break;
case 's': dir = DOWN; break;
case 'x': gameOver = 1; break;
}
}
}
void Logic() {
int prevX = tailX[0];
int prevY = tailY[0];
int prev2X, prev2Y;
tailX[0] = x;
tailY[0] = y;
}
int main() {
Setup();
while (!gameOver) {
Draw();
Input();
Logic();
usleep(150000);
}
printf("Game Over! Final Score = %d\n", score);
return 0;
}