Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8730483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:01:51+00:00 2026-06-13T09:01:51+00:00

I’m writing a little program in C, for check the HTML file have the

  • 0

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):

<a>
</a>
<abbr>
</abbr>
<area>
</area>
<aside>
</aside>

and i have the htmlfile.html, what I have to check:

<!--#echo var="date" -->
<area>
</area>
<area>
</area>

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

my code:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

#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 < 2)
    {
            printf("\npress a button:\n\n");

                    printf("\tFile HTML check..............:c\n");
                    printf("\t<!--#echo var="date" -->...........: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<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]=="<" )
        {

                while(currentline[j]!=">") 
                {
                    htmlfiletags[k][j]=currentline[j];
                    ++j;
                }
                strcat(htmlfiletags[k][j+1],">"); 
                ++k; 
        }
}
printf("\tcheck__3\n");


 int n;
 for(n=0; n<sizeof(htmlfiletags); ++n)
 {
     int j; int howmanytimesnot=0;

     for(j=0; j<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<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(&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[]="<!--#echo var=date -->";

    while(fgets(line,sizeof(line),htmlfile) != NULL)
    {

            if( strcmp(line,"<!--#echo var="date" -->") == 0 )
            {

            char row[40];
            strcpy(row,"<!--");
            strcat(row, date_time);
            strcat(row,"-->");

    printf("%s",row);
            fputs(row,tempfile);

            }
            else
            {
                    fputs(line,tempfile);
            }
    }

    fclose(htmlfile);
    fclose(tempfile);

    copy_file("tempfile.html","htmlfile.html");

}

it dies in this, in the inner for loop, in the if at the 200th check… i dont know why…

 int n;
 for(n=0; n<sizeof(htmlfiletags); ++n)
 {
     int j; int howmanytimesnot=0;

     for(j=0; j<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<sizeof(tags)))
        {
            printf("\tcheck__3/4\n");
          printf("the file is not wellformed");

          exit (1);
        }

 }

Thanks for all reply!!
G

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:01:52+00:00Added an answer on June 13, 2026 at 9:01 am

    Your code is very complicated, it has several issues.

    Here’s one:

    for(j=0; j<sizeof(tags); ++j)
    

    this will not do what I believe you expect; sizeof(tags) is not the array length of tags (which is declared as char tags[189][30];), it’s the total size of the variable. So, this loop will go from 0 to 189 * 30 – 1, i.e. 5669, and thus index way out beyond the end of array.

    Also, the idea to use sizeof here in any way is wrong, since the content of tags comes from a file and it thus impossible for the compiler to know. Remember that sizeof is evaluated at compile-time, for expressions like these.

    You need to have a variable (e.g. size_t num_tags) that you increment for each line parsed from the tags file, and that you later use to iterate over tags.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
i got an object with contents of html markup in it, for example: string
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.