Algorithms
Electronics
File Formats
Freeware
Games Programming
Hardware/Architecture
HTML/CCS & Java/Javascript
Humour
Link Site,Library
Linux,GNU
Magazines/Books
Network Protocols
Networks
New/Latest Stuff
Programming Languages
Servers/ISAPI/ IO Completion Ports
Sound/Music and Multimedia
Source Code
Visual Basic
Windows
Winsock

Converting Files to HTML - Part 1

You may think that you can just copy a text file and paste it into a HTML file and with the standard tags and have no trouble. This may work some of the time, but there are some characters that cannot be used in the text of a HTML file. An example of this is < and >.

The program shown below reads the file in from STDIO and outputs it to STDOUT.

#include <windows.h>
#include <stdio.h>

int main()
{
int ch;
while((ch =getchar()) != EOF)
   {
   if((ch >='0' && ch<=';') || (toupper(ch)>='A' && toupper(ch)<='Z') || ch==10 || ch==13)
       putchar(ch);
   else printf("&#%d;",ch);
   }
}
The program above does convert text to HTML properly, although it is not the best because some of the characters converted have other representations that are more human readable.

Copyright Geoffrey Smith 2000