2

I have to make html website in which I have to put all the C /C++ /Java Codes But when I put C code in html tag , the C librabry <stdio.h> itself treated as a html tag due to angular brackets. What should I do to treat <stdio.h> as a simple text and not as a html tag ?

 <!DOCTYPE html>
    <html lang="en">
        <meta charset="UTF-8">
        <head>
            <title>
                codes
            </title>
            <script src="" ,type="text/javascript">
                
            </script>
        </head>
        <body>
            <pre id="sumof2num">
                <code>
                #include<stdio.h>
                    
                    int main()  
                    { 
                        int a; 
                        int b; //declaring vars
                        int sum=0; //initializing vars
                        printf("Enter Two Numbers: \n");
                        scanf("%d%d",&a,&b);
                        sum=a+b;
                        printf("Sum is %d",sum);                    
                        return 0;
                    }
                </code>
                </pre> 
        </body>
    </html>
  • use [HighlightJS](https://highlightjs.org/). – Kunal Tanwar Aug 15 '21 at 05:13
  • Replacing the angle brackets with their equivalent HTML character sequences is given as an answer (multiple times) at https://stackoverflow.com/questions/3505047/printing-html-using-html – A Haworth Aug 15 '21 at 06:55

1 Answers1

2

if you mean you want to display <> symbols in code then try < and >. While rendering as HTML it will be converted into <> symbols.

<html lang="en">
    <meta charset="UTF-8">
    <head>
        <title>
            codes
        </title>
        <script src="" ,type="text/javascript">
            
        </script>
    </head>
    <body>
        <pre id="sumof2num">
            <code>
            #include &lt;stdio.h&gt;
                
                int main()  
                { 
                    int a; 
                    int b; //declaring vars
                    int sum=0; //initializing vars
                    printf("Enter Two Numbers: \n");
                    scanf("%d%d",&a,&b);
                    sum=a+b;
                    printf("Sum is %d",sum);                    
                    return 0;
                }
            </code>
            </pre> 
    </body>
</html>
Amit Verma
  • 2,450
  • 2
  • 8
  • 21