How do I link C programming compiler to C2

0 favourites
  • 4 posts
From the Asset Store
Firebase: Analytics, Dynamic Links, Remote Config, Performance, Crashlytics on Android, iOS & Web Browser
  • I want to make a educational game which teaches C programming language I want the players can edit C code on my game and send code file to run on compiler then send back the result from complied Please help me how I can do

    Thank you

  • if you're running with nwjs you can call an external application to do this for you. If you're running on the web you'd have to send the data to a server and then run the compiler on the server.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • if you're running with nwjs you can call an external application to do this for you. If you're running on the web you'd have to send the data to a server and then run the compiler on the server.

    Thank you so much for reply, briggybros

    I am running my game on web but I don't know how to send the data from C2 to a server and then run the compiler . What I should to know before do it such as a how to or the name of compiler. I spanned time all week for solve this issue but I can't, please help me or tell me more about the process or step Thank you again.

  • so the solution from the top of my head would be to rent a server with a linux distribution, making sure you have gcc installed, and configure a webserver with a large post length. Then in your app, you can use construct's urlencode() on the entire source code and use AJAX post to url to post the encoded source code to a webpage with a php script something like the following:

    <?php
    
    function checkSource($source) {
    	//TODO: Definitely check here if the C program will not try to kill your server.
    	$safe = true;
    	return $safe ? $source : '#include<stdio.h> \n main(){printf("Illegal C Program!");}';
    }
    
    $name = "tempfile" . rand(0, 100000);
    file_put_contents($name . ".c", checkSource(urldecode($_POST['source'])));
    $res = shell_exec("gcc" . $name . ".c -o " . $name);
    if ($res == NULL) {
    	print("Compilation error");
    } else {
    	print (exec("./" . $name));
    }
    ?>
    [/code:3k38v8fu]
    
    I cannot stress the importance of checking whether the C file will not break your system, and personally I would never allow a script like this to be on my server, as it's prone to so much abuse.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)