Ian Mbae
Ian Mbae

Reputation: 146

Is it possible to embed c code in an HTML page and if it is, how so?

I am a seeking to make a UI for my C school project and I am proficient in HTML CSS Js JQuery.

anybody know any way that I can 'embed' C in HTML?

Upvotes: 4

Views: 16513

Answers (4)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201568

You can include or embed C code in an HTML document, but it will not do anything; it will taken just as text data.

There is no support in browsers for using C as client-side scripting language. Theoretically, you could write an interpreter for C (or a subset of C) in JavaScript. Or even a browser that has native C support...

On the more practical side, you can use C as server-side programming language. It would then normally be used via CGI (Common Gateway Interface), but then you need support for this on the server you use. And it would not be particularly efficient especially for implementing a UI, since processing any user action would require an HTTP request and would launch a new process on the server, running the compiled C program, which would then send the result back to the browser.

So you probably don’t want to use C in this context. But if you still consider it, check my dusty old page Getting Started with CGI Programming in C.

Upvotes: 3

RocketMaker69
RocketMaker69

Reputation: 27

You can use PHP's shell_exec() like this:

<!DOCTYPE html>
<body>
    <?php shell_exec("python your_file_here.py") ?>
</body>

Upvotes: 0

Andy Hu
Andy Hu

Reputation: 11

You can compile portable C code into web assembly, then embed it into HTML.

A compiler that compiles into web assembly: https://emscripten.org/docs/introducing_emscripten/about_emscripten.html

web assembly: https://webassembly.org/

Upvotes: 1

You can write CGI scripts in any language, including C.

Upvotes: 3

Related Questions