How to enter a C program in an Html File without problems?

This is a discussion on How to enter a C program in an Html File without problems? within the Tech Board forums, part of the Community Boards category; I have been writing quite some programs lately. Now, I have a problem here. While creating Web Pages to host ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    47

    How to enter a C program in an Html File without problems?

    I have been writing quite some programs lately.

    Now, I have a problem here. While creating Web Pages to host the C Code, I run into problems like <stdio.h> cannot be seen.

    The reason being the angle brackets are a part of the HTML Code, and anything put in those brackets and which doesn't make sense, will not be accepted.

    The only solution to the problem would be to write < stdio.h > maybe!
    (Write it with some spaces! )


    I would like to ask if there is any way to produce the C Code untouched by the HTML Code?

    Like is there is anything like <code> </code> or something like that in HTML?

    Any ideas would be appreciated.

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    You can either use <noscript> </noscript> or something like this or (better) use &lt; for < and &gt; for >.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    I tried the <noscript> option. But that did not help. With this one, the Code itself cannot be seen!

    or (better) use &lt; for < and &gt; for >.
    Not sure how to use it.
    I am not a very good HTML Programmer. I just know some some of the basics.
    Last edited by duffmckagan; 06-26-2006 at 09:21 PM.

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,738
    &lt; &gt; You would just type those in the document and they should work.
    Alternatively you can just use

    <textarea>
    code
    </textarea>

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    Nope...

    With that textarea thing, it is simply enclosed in a box. The box is too small to view the entire code..and it has scroll bars on the side. (I don't want the scroll bars thing. )


    Also, I tried the &lt; thing....No luck.

    It just encloses the code in

    <
    code
    > ..two angle brackets as shown ..but it doesn't take care of the <stdio.h>It still cannot be seen!


    I am trying to post the program on my Blog @ Blogger.
    See if that would need any specific instructions!

  6. #6
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,738
    Okay.

    Textarea is a container. In html all containers are resizable by setting attributes like height and width, but I'm not sure it will work at places like blogger. Blah.

    Code:
    #include &lt;stdio.h&gt;
    
    int main(void) {
       puts("hello world");
       return 0;
    }
    QED.

    I used to want a website once, but the internet has enough of everything.

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    Okay!

    I got you...

    Now I understand how you wanted me to use the &lt; &gt; thing.

    Thanks.

    After all, it is the thing that is viewable that matters.

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    I've always used the code2html program. Not only will it escape the necessary html characters, but it will also do syntax highlighting, and preserve tabs.

    EDIT:Take a look at this example to see code2html at work.
    Last edited by bithub; 06-26-2006 at 10:12 PM.

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,883
    I've always used the code2html program. Not only will it escape the necessary html characters, but it will also do syntax highlighting, and preserve tabs.
    Its liberal use of the font tag, which is deprecated, is rather disturbing.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    Okay..I will try that.

  11. #11
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    Okay...This is a good one for the added advantage.

    It highlights the code...

    But the thing that i was looking for is already told by citizen (The use of &lt; and &gt; )

    Code2HTML does the same thing!

    <font color="0000ff"><strong>#include<font color="#008000">&lt;stdio.h&gt;</font></strong></font>
    Notice the stdio.h.

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I would like to ask if there is any way to produce the C Code untouched by the HTML Code?
    I run mine through a formatting program that escapes HTML characters and adds CSS coloring and throws everything between <pre></pre> tags. So this:
    Code:
    struct jsw_node *jsw_insert ( struct jsw_node *root, int data )
    {
      if ( root == nil )
        root = make_node ( data, 1 );
      else {
        struct jsw_node *it = root;
        struct jsw_node *up[32];
        int top = 0, dir = 0;
    
        for ( ; ; ) {
          up[top++] = it;
          dir = it->data < data;
    
          if ( it->link[dir] == nil )
            break;
    
          it = it->link[dir];
        }
    
        it->link[dir] = make_node ( data, 1 );
    
        while ( --top >= 0 ) {
          if ( top != 0 )
            dir = up[top - 1]->link[1] == up[top];
    
          up[top] = skew ( up[top] );
          up[top] = split ( up[top] );
    
          if ( top != 0 )
            up[top - 1]->link[dir] = up[top];
          else
            root = up[top];
        }
      }
    
      return root;
    }
    Becomes this:
    Code:
    <pre class="code scroll">
    <span class="keyword">struct</span> jsw_node *jsw_insert ( <span class="keyword">struct</span> jsw_node *root, <span class="keyword">int</span> data )
    {
      <span class="keyword">if</span> ( root == nil )
        root = make_node ( data, <span class="number">1</span> );
      <span class="keyword">else</span> {
        <span class="keyword">struct</span> jsw_node *it = root;
        <span class="keyword">struct</span> jsw_node *up[<span class="number">32</span>];
        <span class="keyword">int</span> top = <span class="number">0</span>, dir = <span class="number">0</span>;
    
        <span class="keyword">for</span> ( ; ; ) {
          up[top++] = it;
          dir = it-&gt;data &lt; data;
    
          <span class="keyword">if</span> ( it-&gt;link[dir] == nil )
            <span class="keyword">break</span>;
    
          it = it-&gt;link[dir];
        }
    
        it-&gt;link[dir] = make_node ( data, <span class="number">1</span> );
    
        <span class="keyword">while</span> ( --top &gt;= <span class="number">0</span> ) {
          <span class="keyword">if</span> ( top != <span class="number">0</span> )
            dir = up[top - <span class="number">1</span>]-&gt;link[<span class="number">1</span>] == up[top];
    
          up[top] = skew ( up[top] );
          up[top] = split ( up[top] );
    
          <span class="keyword">if</span> ( top != <span class="number">0</span> )
            up[top - <span class="number">1</span>]-&gt;link[dir] = up[top];
          <span class="keyword">else</span>
            root = up[top];
        }
      }
    
      <span class="keyword">return</span> root;
    }
    </pre>
    I've only had to fix a couple of bugs, but it hasn't been tested thoroughly. If I remember, I'll attach the code when I get home tonight. Naturally, the CSS doesn't do anything unless you define it elsewhere.
    My best code is written with the delete key.

  13. #13
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Dev-C++ will convert code to HTML. So will lots of other editors; SciTE and ConTEXT and Crimson come to mind.

    I wrote my own code formatter, but it was a while ago and the data files use <font> too.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  14. #14
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    I will try those compilers. I am using Microsoft Visual Studio C++ at the time.

    On Linux, I am using Anjuta.

  15. #15
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Strange - usually learning goes this way:
    HTML+CSS+Javascript -> PHP or CGI -> Something more -> C++ or C

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Need Help With a BlackJack Program in C
    By Jp2009 in forum C Programming
    Replies: 15
    Last Post: 03-30-2009, 10:06 AM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. File I/O problems!!! Help!!!
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-17-2002, 08:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21