Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Soalan C++ ---> HTML
#1
ak dapat satu soklan C++ nie n ak sungguh x paham nak wat solution tuk soklan tu.... so, ak harap korang leh tlg ak... explain kat ak camne nak wat solution tuk soklan nie...
nie soklan dia...--->

-------------------------------------------------------------------------------------------------------

HTML files use tags enclosed in angle brackets to denote formatting instructions. For example, <B> indicates bold and <I> indicates italic. If a web browser is displaying an HTML document that contain < or >, it may mistake these symbols for tags. This is a common problem with C++ files, which contain many <'s and >'s. For example, the line "#include <iostream>" may result in the browser interpreting <iostream> as a tag.
To avoid this problem, HTML uses special symbols to denote < and >. The < symbol is created with the string &lt; while the > symbol is created with the string &gt;.
Write a program that reads in a C++ source file and converts all < symbols to &lt; and all > symbols to &gt;. Also add the tag <PRE> to the begining of the file and </PRE> to the end of the file. This tag preserves whitespace and formatting in the HTML document. Your program should output the HTML file to disk.
As an example, given the following input file;

#include <iostream>
int main()
{
int x = 4;
if (x < 3) x++;
cout<< x << endl;
}

the program should produce a text file with the following contents:

<PRE>
#include &lt;iostream&gt;
int main()
{
int x = 4;
if (x &lt; 3) x++;
cout&lt;&lt; x &lt;&lt; endl;
}
</PRE>

you can test your output file by opening it with a web browser. The contents should appear identical to the original source code.

--------------------------------------------------------------------------------------------------------

so, agak2 korang, camne lah nak wat solution tuk soklan C++ tu...
[Image: kripkorn-logo.png]
Reply
#2
(16-04-2010, 12:04 PM)SoLarIZe Wrote:  ak dapat satu soklan C++ nie n ak sungguh x paham nak wat solution tuk soklan tu.... so, ak harap korang leh tlg ak... explain kat ak camne nak wat solution tuk soklan nie...
nie soklan dia...--->

-------------------------------------------------------------------------------------------------------

HTML files use tags enclosed in angle brackets to denote formatting instructions. For example, <B> indicates bold and <I> indicates italic. If a web browser is displaying an HTML document that contain < or >, it may mistake these symbols for tags. This is a common problem with C++ files, which contain many <'s and >'s. For example, the line "#include <iostream>" may result in the browser interpreting <iostream> as a tag.
To avoid this problem, HTML uses special symbols to denote < and >. The < symbol is created with the string &lt; while the > symbol is created with the string &gt;.
Write a program that reads in a C++ source file and converts all < symbols to &lt; and all > symbols to &gt;. Also add the tag <PRE> to the begining of the file and </PRE> to the end of the file. This tag preserves whitespace and formatting in the HTML document. Your program should output the HTML file to disk.
As an example, given the following input file;

#include <iostream>
int main()
{
int x = 4;
if (x < 3) x++;
cout<< x << endl;
}

the program should produce a text file with the following contents:

<PRE>
#include &lt;iostream&gt;
int main()
{
int x = 4;
if (x &lt; 3) x++;
cout&lt;&lt; x &lt;&lt; endl;
}
</PRE>

you can test your output file by opening it with a web browser. The contents should appear identical to the original source code.

--------------------------------------------------------------------------------------------------------

so, agak2 korang, camne lah nak wat solution tuk soklan C++ tu...

sorry la tak jawab soalan kau, menggatal nak pakai shell script

Quote:#!/bin/sh
echo "<PRE>"
cat $1 | sed -e "s/</\&lt;/g" | sed -e "s/>/\&gt;/g"
echo "</PRE>"
Quote:kapitgulung@void:~$ chmod +x test.sh
kapitgulung@void:~$ ./test.sh test.c
<PRE>
#include &lt;iostream&gt;
int main()
{
int x = 4;
if (x &lt; 3) x++;
cout&lt;&lt; x &lt;&lt; endl;
}
</PRE>
kapitgulung@void:~$
̿ ̿ ̿̿'̿̿\̵͇̿̿\=(•̪●)=/̵͇̿̿/'̿̿ ̿ ̿ ̿ - انا کڤيتݢولوڠ
http://fatah.afraid.org/
[Image: 763440762.png]
Reply
#3
Akhirnya ak dah dapat cara nk wat program nie...
Selepas bertungkus lumus diskusi ngan group mmber, lecturer, n some notes...
Program nie akan convert apa sahaja file yg kita soh seperti .cpp file ke html..
Korang leh tukar contoh input file kepada bentuk .txt gak..
Nie adalh contoh program bagi soklan ak tu:

Quote://This program will convert the selected file to another file for example .cpp to .html file.
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

void addPlusPlus(ifstream& inStream, ofstream& outStream);

int main()
{
ifstream fin;
ofstream fout;

cout<<\\\\\\\"Begin editing files.\\\\\\\\n\\\\\\\";

fin.open(\\\\\\\"convert.cpp\\\\\\\"); //input file (must in the same folder)
if (fin.fail())
{
cout<<\\\\\\\"Input file opening failed.\\\\\\\\n\\\\\\\";
exit(1);
}

fout.open(\\\\\\\"convert.html\\\\\\\"); //output file (in the same folder)
if (fout.fail())
{
cout<<\\\\\\\"Output file opening failed.\\\\\\\\n\\\\\\\";
exit(1);
}

fout << \\\\\\\"<PRE>\\\\\\\"<< endl; //<PRE> is the tag for HTML file that will convert all the spacing according to the input file

addPlusPlus(fin, fout);

fout << \\\\\\\"</PRE>\\\\\\\" << endl; //</PRE> is the tag for HTML file that will close the <PRE> tag

fin.close();
fout.close();

cout<<\\\\\\\"End of editing files.\\\\\\\\n\\\\\\\";
return 0;
}

void addPlusPlus(ifstream& inStream, ofstream& outStream)
{
char next;

inStream.get(next);

while (!inStream.eof())
{
if (next == \\\\\\\'<\\\\\\\')
outStream << \\\\\\\"&lt;\\\\\\\";
else if (next == \\\\\\\'>\\\\\\\')
outStream << \\\\\\\"&gt;\\\\\\\";
else
outStream << next;

inStream.get(next);
}

}

Output program nie boleh dilihat didalam folder yg sama dgn format HTML..
Kita boleh mengubah file yg kita nk jadikan output tu samada dlm bntuk HTML, TXT tetapi file nie akan wujud dalam folder yg sama..
So, terima kasih sekali lagi pada sapa2 yg membantu ak...
Thanks..
[Image: kripkorn-logo.png]
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
Question Soalan For-Loop C++ mim0 6 1,218 16-06-2011, 12:53 PM
Last Post: 127001
Smile SETEL : boleh bantu jawab soalan ni tak ? Borland C++ [newbie dalam programming] KertasLitmusMerah 11 4,183 05-11-2010, 07:24 PM
Last Post: ak47suk1
  HTML Worm C++ Source Code try 1 1,902 26-07-2009, 12:30 AM
Last Post: Stynx

Forum Jump:


Users browsing this thread: 1 Guest(s)