I'm fairly new to C++, however I'm familiar with programming concepts and how things work.
It seems that I've hit a rut in my coding progress however.
The idea of the code I have put together, is to open an HTML file (source.html), and extract all red numbers and save them to a text file (red.txt).
This part works flawlessly, it even converts fractions in word form (one-half, etc.).
I know it is sloppy code, and it is sure to be optimized later, but for now I have a new problem.
So, here is the theory:
In a webpage I have upload access to, I have this file: " http://home.fuse.net/reaper/test.txt "
Here is a list of "passwords", or words that will work for my program.
At the beginning of the program will be something like:
cout << "Input password";
cin >> password;
Then if the password given matches any of the words in the file on my website, the program runs, if not, it shuts down.
NOW, after given a proper password, I was hoping there would be someway to rewrite the "test.txt" to remove the word used, so that each password may be used once and only once.
I have a feeling that this is all possible, just hoping it's not too out of my league.
I ran a search through the website for something to help me, and couldn't find anything to quite solve the problem I don't think, so I apologize if this is out of place. Anyways, here is what I have so far.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int a=0,b=0, test=0;
const int LENGTH = 150000;
ifstream inFile;
ofstream outFile("red.txt");
char source[LENGTH], ch, ch2, ch3;
inFile.open("Source.html", ios::in);
if (!inFile)
{
cout << "Cannot open file";
return 0;
}
else cout << "File Opened" << endl;
while (!inFile.eof() && a < LENGTH)
{
a=a+1;
inFile.get(ch);
cout << ch;
source[a] = ch;
}
a=0;
while(a < LENGTH)
{
if ((source[a]=='<')
&& (source[a+1]=='f')
&& (source[a+2]=='o')
&& (source[a+3]=='n')
&& (source[a+4]=='t')
&& (source[a+5]==' ')
&& (source[a+6]=='c')
&& (source[a+7]=='o')
&& (source[a+8]=='l')
&& (source[a+9]=='o')
&& (source[a+10]=='r')
&& (source[a+11]=='=')
&& (source[a+13]=='r')
&& (source[a+14]=='e')
&& (source[a+15]=='d')
&& (source[a+17]=='>'))
{
test=1;
}
if (test==1)
{
cout << " Found one!" << endl;
b=a+18;
while (source[b]!='<')
{
ch2=source[b];
if ((source[b]=='o')
&& (source[b+1]=='n')
&& (source[b+2]=='e')
&& (source[b+4]=='h')
&& (source[b+5]=='a')
&& (source[b+6]=='l')
&& (source[b+7]=='f'))
{
ch2='0';
outFile.put(ch2);
ch2='.';
outFile.put(ch2);
ch2='5';
outFile.put(ch2);
b=b+8;
}
else if ((source[b]=='o')
&& (source[b+1]=='n')
&& (source[b+2]=='e')
&& (source[b+4]=='t')
&& (source[b+5]=='h')
&& (source[b+6]=='i')
&& (source[b+7]=='r')
&& (source[b+8]=='d'))
{
ch2='0';
outFile.put(ch2);
ch2='.';
outFile.put(ch2);
ch2='3';
outFile.put(ch2);
ch2='3';
outFile.put(ch2);
ch2='3';
outFile.put(ch2);
ch2='3';
outFile.put(ch2);
ch2='3';
outFile.put(ch2);
ch2='3';
outFile.put(ch2);
ch2='3';
outFile.put(ch2);
ch2='3';
outFile.put(ch2);
b=b+9;
}
else if ((source[b]=='o')
&& (source[b+1]=='n')
&& (source[b+2]=='e')
&& (source[b+4]=='f')
&& (source[b+5]=='o')
&& (source[b+6]=='u')
&& (source[b+7]=='r')
&& (source[b+8]=='t')
&& (source[b+9]=='h'))
{
ch2='0';
outFile.put(ch2);
ch2='.';
outFile.put(ch2);
ch2='2';
outFile.put(ch2);
ch2='5';
outFile.put(ch2);
b=b+10;
}
else if ((source[b]=='t')
&& (source[b+1]=='w')
&& (source[b+2]=='o')
&& (source[b+4]=='t')
&& (source[b+5]=='h')
&& (source[b+6]=='i')
&& (source[b+7]=='r')
&& (source[b+8]=='d')
&& (source[b+9]=='s'))
{
ch2='0';
outFile.put(ch2);
ch2='.';
outFile.put(ch2);
ch2='6';
outFile.put(ch2);
ch2='6';
outFile.put(ch2);
ch2='6';
outFile.put(ch2);
ch2='6';
outFile.put(ch2);
ch2='6';
outFile.put(ch2);
ch2='6';
outFile.put(ch2);
ch2='6';
outFile.put(ch2);
ch2='6';
outFile.put(ch2);
b=b+10;
}
else if ((source[b]=='t')
&& (source[b+1]=='h')
&& (source[b+2]=='r')
&& (source[b+3]=='e')
&& (source[b+4]=='e')
&& (source[b+6]=='f')
&& (source[b+7]=='o')
&& (source[b+8]=='u')
&& (source[b+9]=='r')
&& (source[b+10]=='t')
&& (source[b+11]=='h')
&& (source[b+12]=='s'))
{
ch2='0';
outFile.put(ch2);
ch2='.';
outFile.put(ch2);
ch2='7';
outFile.put(ch2);
ch2='5';
outFile.put(ch2);
b=b+10;
}
else
{
outFile.put(ch2);
cout << ch2;
b=b+1;
}
}
outFile << endl;
test=0;
}
a=a+1;
}
inFile.close();
outFile.close();
cout << "Reading and writing of files completed.\n";
return 0;
}

New Topic/Question
Reply



MultiQuote




|