Hi i have my code that finds every instance of my search criteria in a text file and tells me the position in the text file it is located at. The next step i want to do is stream the bytes that follow each instance of my search criteria into a new file until it reaches another search criteria.
My example is that i have lots of jpeg's inside a text file full of data. I presently search for the start of every picture. I then want to stream the data into a new file until i reach the end of every picture and recreate all the pictures that may be embedded in the text file. I hope im explaining myself well enough.
Can anyone show me how to set up a file stream that will start at every point of my search criteria and stop and the end of the data i need which is my 'match_criteria1'
thanks
static char match_criteria1[] = { 0xFF, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static char match_criteria[] = { 0xFF, 0xD8, 0xFF, 0xC0 };
size_t buf_len = (sizeof( match_criteria )/sizeof( char ));
char* p_read_buffer = new char[buf_len];
size_t buf_len1 = (sizeof( match_criteria1 )/sizeof( char ));
char* p_read_buffer1 = new char[buf_len1];
int pos = 0;
bool matched = false;
cout << "Enter the name of the file you wish to open: ";
string filename;
getline( cin, filename );
ifstream infile( filename.c_str(), ios::binary );
int position = 0;
while( infile.is_open() && infile.good() && !infile.eof() && !infile.fail() && !infile.bad() )
{
infile.seekg(position, ios::beg);
infile.read( p_read_buffer, buf_len );
if( infile.eof() || infile.fail() || infile.bad() )
{
infile.close();
}
else if( memcmp( p_read_buffer, match_criteria, buf_len ) == 0 )
{
matched = true;
pos = infile.tellg();
pos -= buf_len;
target_file.seekg (pos,std::ios::beg) ;
cout << "File: " << filename << " match search criteria at position: " << pos << endl;
}
position++;
}