How do you include a HTML file in c

2.4k views Asked by At

I am currently using g-wan for myweb server and would like to know How do you merger multiple HTML files, in c for HTML?
In php I t would be

<?php include('/path/to/file.php');?>

How would you do this in c for gwan?

1

There are 1 answers

3
Gil On BEST ANSWER

The PHP include statement loads a static file from disk to build the PHP output. The included file can be both PHP code or HTML text. The PHP pre-processor will just blindly load the file and let it be interpreted by the PHP interpreter.

The C language can be the same thing for C source code with the #include directive, but not for raw HTML text, unless it has been placed in a C array (as shown here in the static char top[] array).

This is the most efficient option because the file is already part of the source code file. The downside is that the contents may be duplicated if you need them from different C scripts.

If this overhead is unacceptable, you can also load the file dynamically (at the cost of more disk I/O) as shown here, search for the xbuf_frfile(&buf, szfile); line of code.

Note that as PHP, an interpreted language, is written in C and/or C++, the PHP include statement is most probably using the C option #2 above, hence the better performance when using PHP code caches because the included file is loaded only one time (at the cost of contents duplication, like the C option #1 describbed above).

To sum it up, C lets you pick the method you want, when you want.