![]() ![]() Let's start coding - create a new folder and within it create an empty file called code2html.c. This causes the executable code2html to convert the source code file code2html.c to the HTML file code2html.c.html. For example, we would convert the source code for this project to HTML with the following. What we need is a simple program which will take an input file as a command line arguments, perform the above substitutions on the input file, and save the result in the output file with the same name as the input file with ".html" suffixed. • The symbols need to be replaced with < and > respectively, or the browser will try to interpret them as HTML tags.If we have code using four spaces instead of tabs for example, these will not render correctly unless we replace each space with. Single spaces are shown correctly by browsers, but multiple spaces are shown as only one space. Code written on a Windows system will have a carriage return as well as a linefeed - these need to be deleted, or specifically replaced with an empty string.The \n isn't necessary for the browser, but does format the raw HTML better. (Of course, you might have different ideas about the size of a tab!) If we don't do this the browser will just show one space. We need to, at the very least, carry out the following substitutions to produce something a browser will render as we want it: The ProblemĬopying and pasting C source code (or any source code for that matter) into an HTML document just isn't going to work. It's not the greatest piece of software ever written but it does the job, so I thought I might as well share it. This would be incredibly tedious to do by hand so I put together a quick and dirty utility to do it for me. All the posts on this blog contain C source code which has been reformatted as HTML. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |