first.c

#include <stdio.h>

void main (void) {
  FILE* myfile;
  int i,j;
  char buffer[80];
  char buff[200];

  printf ("Content-type: text/html\n\n");
  printf ("<html>\n");
  printf ("<head><title>First CGI in C</title></head>\n");
  printf ("<body bgcolor=#ffffff\n");
  printf ("<h1>Hello World!</h1>\n");
  printf ("<hr><h2>The code that generated this output was</h2>\n");
  printf ("<pre>\n");
  if ((myfile=fopen("first.c","r"))==0) 
    printf ("<h1> Can not open first.c </h1>\n");
  else
    while (fgets(buffer,80,myfile) !=NULL) {
      j=0;
      for (i=0; i<=strlen(buffer);i++) {
        if (buffer[i]=='&') {
          buff[j]='&';
          buff[j+1]='a';
          buff[j+2]='m';
          buff[j+3]='p';
          buff[j+4]=';'; 
          j+=5;
        } else if (buffer[i]=='<') {
          buff[j]='&';
          buff[j+1]='l';
          buff[j+2]='t';
          buff[j+3]=';';
          j+=4;
        } else if (buffer[i]=='>') {
          buff[j]='&';
          buff[j+1]='g';
          buff[j+2]='t';
          buff[j+3]=';';
          j+=4;
        } else {
          buff[j]=buffer[i];
          j++;
        }
      }
      printf("%s",buff);
  }
  fclose(myfile);
  printf ("</pre>\n");
  printf ("</body>\n</html>\n");
  
}