--- title: "STRIPHTML_C" type: "article" slug: "striphtml_c" url: "http://localhost/article/striphtml_c/" markdown_url: "http://localhost/article/striphtml_c.md" published_at: "2025-12-18T18:37:26+00:00" modified_at: "2026-06-21T23:26:43+00:00" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "With the popularity of the World Wide Web, more and more information is being formatted in HTML, the \"language\" of the Web. Since HTML is pure ASCII this is not a problem for people that don't' have Web Browsers. But, HTML commands can make text look very convoluted. The following C program will read a…" category: - name: "QL Hacker's Journal" slug: "ql-hackers-journal" taxonomy: "category" url: "http://localhost/category/periodicals/ql-hackers-journal/" post_tag: - name: "C (programming language)" slug: "c-programming-language" taxonomy: "post_tag" url: "http://localhost/tag/c-programming-language/" - name: "Full Text" slug: "fulltext" taxonomy: "post_tag" url: "http://localhost/tag/fulltext/" - name: "QL" slug: "ql" taxonomy: "post_tag" url: "http://localhost/tag/ql/" model: - name: "Sinclair QL" slug: "sinclair-ql" taxonomy: "model" url: "http://localhost/model/sinclair-ql/" indiv: - name: "Tim Swenson" slug: "tim-swenson" taxonomy: "indiv" url: "http://localhost/indiv/tim-swenson/" publication_r: id: 33686 title: "QL Hacker’s Journal" type: "periodical" url: "http://localhost/periodical/ql-hackers-journal/" authors_r: - name: "Tim Swenson" slug: "tim-swenson" taxonomy: "indiv" url: "http://localhost/indiv/tim-swenson/" issue: "23" issues_articles: - id: 61559 title: "QL Hacker’s Journal 23" type: "issue" url: "http://localhost/issue/ql-hackers-journal-23/" pubdate: "January 1996" archive_link: true --- # STRIPHTML_C With the popularity of the World Wide Web, more and more information is being formatted in HTML, the “language” of the Web. Since HTML is pure ASCII this is not a problem for people that don’t’ have Web Browsers. But, HTML commands can make text look very convoluted. The following C program will read a file with HTML commands and strip them out and print out only the text information. Since HTML commands all start with a less-than sign ( < ), and end with a greater-than sign ( > ), striping out the HTML is relatively easy to do: as you read in characters and echo them to the output file, turn off echoing when you see a < and turn it back on when you see a >. The end result will be a regular ASCII file. It may not be formatted to look nice, but the HTML stuff will be gone. ``` /* striphtml_c This program takes in a file with HTML commands and outputs a file with the HTML commands stripped out. */ #include main() { char c, file1[30], file2[30]; int fd1, fd2, html; printf("Enter Input File Name : \n"); gets(file1); printf("Enter Output File Name: \n"); gets(file2); fd1 = fopen(file1,"r"); if (fd1 == NULL) { printf("Did not open file: %s",file1); abort(1); } fd2 = fopen(file2,"w"); if (fd2 == NULL) { printf("Did not open file: %s",file2); abort(1); } html = NO; while (( c = getc(fd1)) != EOF) { if ( html == NO ) { if ( c == '<' ) html = YES; else putc(c,fd2); } if ( html == YES ) { if ( c == '>' ) html = NO; } } fclose(fd1); fclose(fd2); } ``` Example HTML file: ``` Title of Document

Level 1 Text

This is a paragraph. This is a paragraph. This is a paragraph that will wrap in the browser until the end paragraph marker.

The Paragraph marker is also used to create a blank line of text.

```