Skip to content

Instantly share code, notes, and snippets.

@navinpai
Created May 15, 2011 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navinpai/972851 to your computer and use it in GitHub Desktop.
Save navinpai/972851 to your computer and use it in GitHub Desktop.
HTML Number to Text
/***********************************************************************************
Basically takes a file with HTML numbers as input and outputs the converted text to another file.
HTML Numbers is:
A A
B A
etc.
Mainly did this to decrypt(?) lyrics from lyrics sites like SongLyrics.com which allow only viewing but not copying of lyrics (The whole GraceNote license thing) eg. http://www.songlyrics.com/flobots/we-are-winning-lyrics/ ... source code of the page shows the lyrics in HTML numbers.
Compiled with Codeblocks v. 8.02
To run, use "executable name i/p-file o/p-file" i.e command line arguments
***********************************************************************************/
#include <iostream>
#include<conio.h>
#include <fstream>
#include <string>
using namespace std;
int main (int argc,char* argv[]) {
string line;char c,d,e;int x;char h;
if(argc<3)
{cout<<"\n\n\t\tProvide filename of HTML op as argument \n\t\tand Output file as 2nd argument\n";
cout<<"\n\t\teg:"<<argv[0]<<" input.txt mylyrics.txt\n";
return 0;
}
ifstream ip (argv[1]);
ofstream op (argv[2]);
if (ip.is_open())
{
while ( ip.good() )
{
ip.read((char*)&c,sizeof(c));
//CASE1
if(c=='&')
{
ip.read((char*)&d,sizeof(d));
if(d=='#');
else
cout<<"&";
}//CASE2
else if(c=='#');
//CASE3
else if(c==';');
else if(c=='<')
{
while(c!='>')
ip.read((char*)&c,sizeof(c));
}
//CASE4
else if(c>='0'&&c<='9')
{x=atoi(&c);
while(d!=';')
{
ip.read((char*)&d,sizeof(d));
if(d==';')
break;
else
{
x=x*10+d-48;
}
}
h=char(x);
op << h;
}
else op<<c;
}
ip.close();
}
else cout << "Unable to open file";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment