Search code examples
ctextformattinghighlighting

How to add formatting data to text output from c program?


I have a command-line C program (DOS/Windows) which produces a hex dump of several records as a .txt file. I am looking for a way to emphasize certain values without resorting to ascii-art.

Is there a combination of readily available viewing programs and byte sequences that would let me highlight/bold/underline certain blocks of text? Bonus points if I can generate it with a simple fprintf or fwrite call.

I guess HTML is an option, but I was hoping for something even simpler, something along the lines of ANSI escape codes.

Any ideas?


And if HTML is the best, what is the minimal header/tail I need to produce a valid document?
(dammit Jim, I'm an embedded programmer, not a web designer)


Solution

  • I work predominately on Linux/Unix systems, so I don't know what kind of support recent versions of the Windows/DOS CMD shell have for ANSI escape codes. I agree that HTML is probably your best bet.

    Minimal HTML document per W3C

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
    
    <html>
      <head>
         <title>An HTML document</title>
      </head>
      <body>
        Body of HTML document
      </body>
    </html>
    

    You could highlight specific elements using either italics (<i> or <em>) or bold (<b> or <strong>).