Posting Code in a Comment

If you want to upload code in a comment, you’ll need to know a wee bit of HTML formatting. That’s because common characters like <, >, and & are interpreted by the web page browser as HTML, not C code.

• Prefix your code by using the <pre> tag. That way all the spaces and indents are retained.

• Postfix your code by using the </pre> tag. That tag marks the end of the preformatted text block.

• If you code uses the < or > symbols, which it will if you’re including any header files, then you need to specify &lt; for < and &gt; for >. If not, the browser would fail to see the following text:


That text above would be interpreted as HTML, which it isn’t. So no text would appear in the comment.

• Remember that your typical for loop uses the < or > characters, so scan for those. Also scan for if, while, and else keywords.

• The code for the & character is &amp;. If you’re doing a logical AND operation, you need two of them: &amp;&amp; for &&.

All these recommendations are optional, but consider using them if you want the code in your comment to be readable.

If you would like to register, drop me an email and I’ll sign you up.