sobota, 28 grudnia 2019

Save from text file to html (c++ function)

#define max_Size 256
void Save_to_HTML(char *text_File, char *new_html_File)
{

    int i,j,line=0;
    fstream file_Text;
    string buff[max_Size];
    file_Text.open(text_File,ios::in);
    while(!file_Text.eof())
    {
        getline(file_Text,buff[line]);
        ++line;
    }
    file_Text.close();
    int sum_Count=line;
    string begin_Page[6]={"<HTML>","<HEAD>","<TITLE>","</TITLE","</HEAD>","<BODY>"};
    string end_Page[2]={"</BODY>","</HTML>"};
    int size_html_Page=sum_Count+6+2;
    string *page_HTML=new string[size_html_Page];
    for(i=0;i<6;i++)
   {
    page_HTML[i]=begin_Page[i];
   }
   for(i=0,j=6;i<sum_Count;i++,j++)
   {
    page_HTML[j]=buff[i]+" <br> ";
   }
   for(i=0,j=6+sum_Count;i<2;i++,j++)
   {
    page_HTML[j]=end_Page[i];
   }
   fstream file_HTML;
   file_HTML.open(new_html_File, ios::out | ios::app);
   if(file_HTML.good() == true)
   {
       for(i=0;i<size_html_Page;i++)
       {
           file_HTML<<page_HTML[i]<<"\n";
       }
       file_HTML.close();
   }
   delete [] page_HTML;

}


int main()
{
 Save_to_HTML("readme.txt","READ2.html");
    return 0;
}

Brak komentarzy:

Prześlij komentarz