Please help in running C/C++ code from my phone

Hi chaps,

I am new to C/C++ and have been learning Code Academy courses. However, I want to implement what I am learning and for that I currently don’t have access to a PC but only my phone. I have downloaded the Turbo C++ app and even C4Droid app (quite similar these two) but when I compile my code (Run) it, it doesn’t go past showing (Drive C is mounted as local directory /sdcard) as shown in the screenshot I have attached.

I do have an SD card where the folder exists with the program saved. I am thinking if this is an error with the code or the compiler. I mean even simple print hello worlds do the same.

The issue:

The code I am trying to compile:

#include <stdio.h>
void main()
    int n, r, npr_var;
    printf("Enter the value of n:");
    scanf("%d", &n);
    printf("\nEnter the value of r:");
    scanf("%d", &r);
    /* nPr is also known as P(n,r), the formula is:
     * P(n,r) = n! / (n - r)! For 0 <= r <= n.
    npr_var = fact(n) / fact(n - r);
    printf("\nThe value of P(%d,%d) is: %d",n,r,npr_var);
// Function for calculating factorial
int fact(int num)
    int k = 1, i;
    // factorial of 0 is 1
    if (num == 0)
        for (i = 1; i <= num; i++)
            k = k * i;

I do understand if someone would say this is your phone which may not have enough resources and is OLD etc (It’s a Galaxy S8) and the program I am trying to compile only calculates a value of (nPr). It should be more then enough to compile or handle Turbo C++ and C4Droid, for instance I’ve tried using PyDroid and that works fine for even more complex Python scripts!

I’m thinking if it’s the sdcard where the code is stored maybe causing issues with writing?

I don’t think that the code has any issues as I’ve triple-checked the syntax and online C compilers are able to run it just as fine but I’d rather have a proper app hence why the question here…

Thanks in advance!

I’m guessing that your screenshot is part of your attempt to follow the instructions from Ninja-IDE?

A quick scout around the Internet has turned up that the DOSBox emulator that they reference (AnDOSBox) hasn’t been updated in 10 years, and there’s numerous reviews suggesting that it’s unstable or outright unusable on newer Android devices. This may be your problem.

Nonetheless, the screen you’re landing on appears to be part of the boot sequence for DOSBox. If it’s not progressing beyond that, then the issue most likely lies with the DOSBox rather than your code. This is because you would need to be in the DOSBox environment and tell it to compile/run your code before anything would happen. It isn’t going to know automatically to do anything purely because your code exists on the SD Card.

(Furthermore, I really wouldn’t recommend trying to learn or implement C/C++ from a phone… I wouldn’t suggest it for any programming tasks, in all honesty, but definitely not for C.)



Yes correct that is what I had followed originally and downloaded it from.

I think you are right as it is still an unofficial port of the desktop Turbo C which is also in the same boat as not being updated in over a decade.

Yep, that is where it gets stuck and doesn’t show anything like a syntax or such e.g. error at line 10. Thanks for your reply though I guess I’ll wait till I get a PC and start from there otherwise I will be very dishearted and give up :frowning:

I was going very upset thinking it may be the code not compiling and me missing the whole concept lol!

Thank you.

1 Like

Also, I’ll make sure to use something a bit more current like Visual Studio, Code Blocks or Eclipse has caught my attention in the future once I am sorted!

1 Like

No, I think it’s far more likely that it’s the environment not launching correctly. :slight_smile:

I don’t know how well it would run/scale on a phone browser, but you might want to look into something like REPLit which has support for C++ and would potentially provide you with an environment in which to practice.

1 Like

Thank you, I’ll have a more detailed look at replit, looks interesting indeed.

1 Like