How to run C on a webpage on Glitch

Here is a little example I made of running C terminal code on glitch.

Step one: Set up your C code.

#include<stdio.h>

int main(void) {
    printf("Hello World\n");
    return 0;
}

Name the file something like “test.c”. You will want to save it in a project the runs php such as lamp-poc.

Step Two: PHP

exec() in php runs code in the shell.

Compile the C and save it to “test”. (This assumes you are using the Linux terminal with gcc installed)

exec("gcc test.c -o test");

Run it and echo the result.

echo exec("./test");

And thats it! Thank you for reading. A full example can be seen here.

2 Likes

great tutorial @RiversideRocks!

1 Like

Thanks! I’ll keep messing around with this.

starts transpiling python to C++ for faster speed

3 Likes

starts to make an online xent runner

3 Likes

Now that would be cool.

2 Likes

Oh it’s comin brotha

2 Likes

The exec() command is very useful.

3 Likes

Aaah, I miss C and C++…

3 Likes

i miss batch… used to use it a lot before they blocked it…

2 Likes

Just a note: You can also do this with C++, you just need to use the version of gcc for C++.

Simply replace gcc with g++ and it should work based on my experience with a brand new ubuntu install.