title: HTML tags check in C
body: <p>I'm writing a little program in C, for check the HTML file have the right open and close tags?
  but i've got some issues...
  i have a file what contains the all possible tags, named tags.txt(those are only the first ones):</p>
  
  <pre><code>&lt;a&gt;
  &lt;/a&gt;
  &lt;abbr&gt;
  &lt;/abbr&gt;
  &lt;area&gt;
  &lt;/area&gt;
  &lt;aside&gt;
  &lt;/aside&gt;
  </code></pre>
  
  <p>and i have the htmlfile.html, what I have to check:</p>
  
  <pre><code>&lt;!--#echo var="date" --&gt;
  &lt;area&gt;
  &lt;/area&gt;
  &lt;area&gt;
  &lt;/area&gt;
  </code></pre>
  
  <p>secondly, i want to replace the comments like this  to the sysdate
  like , the format is OK i can do it, but the prog puts in the file
  this 
  
  <p>my code:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;time.h&gt;
  
  #define MAX_SIZE 512
  
  
  void menu();
  void check();
  void datumos();
  
  
  int main(int argc,char *argv[])
  {
      menu();
  
      return 0;
  }
  
  void menu()
  {
      char menu[MAX_SIZE];
      while(1 &lt; 2)
      {
              printf("\npress a button:\n\n");
  
                      printf("\tFile HTML check..............:c\n");
                      printf("\t&lt;!--#echo var="date" --&gt;...........:d\n");
                      printf("\tExit:\tCTRL + C\n");
                      scanf("%s",menu);
  
              if( strcmp(menu,"c") == 0 )
              {
                      check();
              }
              else if( strcmp(menu,"d") == 0 )
              {
                      datumos();
              }
  
      }
  }
  
  void check()
  {
      FILE *htmlfile;
      FILE *checkfile;
  
      htmlfile = fopen("htmlfile.html","w");
      checkfile = fopen("tags.txt","r");
  
  char line[MAX_SIZE];
  char htmlline[MAX_SIZE];
  char tags[189][30];
  
  
  int i=0;
  
  printf("\tcheck__1\n");
  
  while(fgets(line,sizeof(line),checkfile) != NULL)
      {
  
          int j;
      for(j=0; j&lt;sizeof(line); ++j)
      {
          tags[i][j]=line[j];
      }
      ++i;
  
      }
  printf("\tcheck__2\n");
  
  
  int k=0;    char htmlfiletags[MAX_SIZE][30];
      while(fgets(htmlline,sizeof(htmlline),htmlfile) != NULL)
      {
      char currentline[sizeof(htmlline)];
      int j=0;
  
          if( currentline[j]=="&lt;" )
          {
  
                  while(currentline[j]!="&gt;") 
                  {
                      htmlfiletags[k][j]=currentline[j];
                      ++j;
                  }
                  strcat(htmlfiletags[k][j+1],"&gt;"); 
                  ++k; 
          }
  }
  printf("\tcheck__3\n");
  
  
   int n;
   for(n=0; n&lt;sizeof(htmlfiletags); ++n)
   {
       int j; int howmanytimesnot=0;
  
       for(j=0; j&lt;sizeof(tags); ++j)
       {
           printf("\tcheck__3/1\n");
  
  
           if(strcmp(htmlfiletags[n],tags[j])==0)
           {
               printf("\t%d\n", howmanytimesnot);
  
               ++howmanytimesnot;
           }
       }
  
      printf("\tcheck__3/3\n");
  
       if(!(howmanytimesnot&lt;sizeof(tags)))
          {
              printf("\tcheck__3/4\n");
            printf("the file is not wellformed");
  
            exit (1);
          }
  
   }
   printf("\tcheck__4\n");
  
  
  }
  
  void copy_file(const char *from,const char *to)
  {
      FILE *fr;
      FILE *t;
      fr = fopen(from,"r");
      t = fopen(to,"w");
  
      char line[MAX_SIZE];
  
      char row[MAX_SIZE];
  
      while(fgets(line,sizeof(line),fr) != NULL)
      {
              sscanf(line,"%s",row);
              fprintf(t,"%s\n",row);
      }
  
      fclose(fr);
      fclose(t);
  
      remove("tempfile.html");
   }
  
  
  void datumos()
  {
  time_t now = time(NULL);
  struct tm *t = localtime(&amp;now);
  char date_time[30];
  strftime( date_time, sizeof(date_time), "%x_%X", t );
  
  FILE *htmlfile;
      FILE *tempfile;
      htmlfile = fopen("htmlfile.html","r");
      tempfile = fopen("tempfile.html","w");
      char line[MAX_SIZE];
      //char datecomment[]="&lt;!--#echo var=date --&gt;";
  
      while(fgets(line,sizeof(line),htmlfile) != NULL)
      {
  
              if( strcmp(line,"&lt;!--#echo var="date" --&gt;") == 0 )
              {
  
              char row[40];
              strcpy(row,"&lt;!--");
              strcat(row, date_time);
              strcat(row,"--&gt;");
  
      printf("%s",row);
              fputs(row,tempfile);
  
              }
              else
              {
                      fputs(line,tempfile);
              }
      }
  
      fclose(htmlfile);
      fclose(tempfile);
  
      copy_file("tempfile.html","htmlfile.html");
  
  }
  </code></pre>
  
  <p>it dies in this, in the inner for loop, in the if at the 200th check... i dont know why...</p>
  
  <pre><code> int n;
   for(n=0; n&lt;sizeof(htmlfiletags); ++n)
   {
       int j; int howmanytimesnot=0;
  
       for(j=0; j&lt;sizeof(tags); ++j)
       {
           printf("\tcheck__3/1\n");
  
  
           if(strcmp(htmlfiletags[n],tags[j])==0)
           {
               printf("\t%d\n", howmanytimesnot);
  
               ++howmanytimesnot;
           }
       }
  
      printf("\tcheck__3/3\n");
  
       if(!(howmanytimesnot&lt;sizeof(tags)))
          {
              printf("\tcheck__3/4\n");
            printf("the file is not wellformed");
  
            exit (1);
          }
  
   }
  </code></pre>
  
  <p>Thanks for all reply!!
  G</p>