Skip to content

Instantly share code, notes, and snippets.

@Raynes Raynes/gist:219998
Created Oct 27, 2009

Embed
What would you like to do?
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const int LENGTH = 81;
ifstream inFile;
fstream outFile("C:\\red.txt", ios::in);
if (!outFile)
{
cout << "Cannot open file";
return 0;
}
char source[LENGTH];
//test each line until end of file
int testNumber = 0;
char finalNum[LENGTH];
while (!outFile.eof())
{
register int tempIndex = 0;
outFile.getline(source, LENGTH, '\n');
testNumber = 0;
for (; source[tempIndex] != '\n' && tempIndex < LENGTH; tempIndex++)
{
//find starting type
if ( (source[tempIndex] == '<')
&& (source[tempIndex + 1] == 'f')
&& (source[tempIndex + 2] == 'o')
&& (source[tempIndex + 3] == 'n')
&& (source[tempIndex + 4] == 't')
&& (source[tempIndex + 5] == ' ')
&& (source[tempIndex + 6] == 'c')
&& (source[tempIndex + 7] == 'o')
&& (source[tempIndex + 8] == 'l')
&& (source[tempIndex + 9] == 'o')
&& (source[tempIndex + 10] == 'r')
&& (source[tempIndex + 11] == '=')
&& (source[tempIndex + 12] == '"' || source[tempIndex + 12] == '\'' )
&& (source[tempIndex + 13] == 'r')
&& (source[tempIndex + 14] == 'e')
&& (source[tempIndex + 15] == 'd')
&& (source[tempIndex + 16] == '"' || source[tempIndex + 16] == '\'' )
&& (source[tempIndex + 17] == '>') )
{
testNumber = 1;
}
//if starting tag was found then, ignore whitespace
if ( testNumber == 1 )
{
tempIndex += 18;
for ( register int placesCount = 0; ( ( source[tempIndex] == ' '
|| source[tempIndex] == '\n'
|| source[tempIndex] == '\t'
|| source[tempIndex] == '\r'
|| source[tempIndex] == ' ' )
|| (source[tempIndex] >= '0' && source[tempIndex] <= '9') )
&& (tempIndex < LENGTH - 6); tempIndex++, placesCount++ )
{
if ( ( source[tempIndex] == ' '
|| source[tempIndex] == '\n'
|| source[tempIndex] == '\t'
|| source[tempIndex] == '\r'
|| source[tempIndex] == ' ' ))
{
tempIndex++;
}
else
{
finalNum[placesCount] = source[tempIndex];
}
//find closing tag
if ( source[tempIndex + 1] == '<' )
{
finalNum[placesCount + 1] = '\0';
tempIndex++;
break;
}//end if
}//end for
//if end tag matched then write to file
if ( (source[tempIndex] == '<')
&& (source[tempIndex + 1] == '/')
&& (source[tempIndex + 2] == 'f')
&& (source[tempIndex + 3] == 'o')
&& (source[tempIndex + 4] == 'n')
&& (source[tempIndex + 5] == 't')
&& (source[tempIndex + 6] == '>') )
{
cout << finalNum << endl; //REPLACE WITH WRITING TO FILE
tempIndex += 6;
}
}//end if
}//end for
tempIndex = 0; //reset index
}//end while
inFile.close();
outFile.close();
cout << "Reading and writing of files completed.\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.